• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /var/www/html/cnasolution/site/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/site/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/site/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

XMLHttpRequest responding with undesired response

I ran into trouble that i have failed to understand at all. I have a sign up form,ajax script and php script.My goal is that,i want to submit data to the php from the sign up form using ajax. My problem is that i can send but do not get the results that i desire as the response. This is my sign-up form

{```















```} And below is my PHP script(action specified by the form): { ```$names = mysqli_real_escape_string($conn, $_POST["names"]); $phone = mysqli_real_escape_string($conn, $_POST["phone"]); $shopName = mysqli_real_escape_string($conn, $_POST["shopName"]); $email = mysqli_real_escape_string($conn, $_POST["email"]); $pwd = mysqli_real_escape_string($conn, $_POST["pwd"]); $pwd2 = mysqli_real_escape_string($conn, $_POST["pwd2"]); $description = mysqli_real_escape_string($conn, $_POST["description"]); //validating the user input data if(!empty($names && $phone && $shopName && $email && $pwd && $pwd2)){ if (preg_match("/^[a-zA-Zs]+$/",$names)) { if (preg_match("/^[0-9+](d)+$/",$phone)) { if(preg_match("/^[a-zA-Zs]+$/",$shopName)) { if(filter_var($email,FILTER_VALIDATE_EMAIL)) { if ($pwd !== $pwd2) { header("Location: ../sell/auth/sell.signup.php?passwordsdoNotMatch"); } else { $hashed_pwd = password_hash($pwd, PASSWORD_DEFAULT); $sql = "INSERT INTO seller(name,phone,shopName,email,password,description,approval_status) VALUES ('$names','$phone','$shopName','$email','$hashed_pwd','$description','0');"; if(!mysqli_query($conn, $sql)){ echo "sorry not added".mysqli_error($conn); }else { header("Location: ../index.php"); $_SESSION['actionmsg-success'] = "successfully Added .Wait for approval!! so that you may post your products."; } }```} And this is the ajax ```function loadFunc(){ const names = document.getElementById('names'); const phone = document.getElementById('phone'); const shopName = document.getElementById('shopName'); const email = document.getElementById('email'); const pwd = document.getElementById('pwd'); const pwd2 = document.getElementById('pwd2'); const description = document.getElementById('description'); var form = document.getElementById('form'); form.addEventListener('submit', function (e) { e.preventDefault(); var params = `names=${names}&phone=${phone},shopName=${shopName},email=${email}&pwd=${pwd}&pwd2=${pwd2}&description=${description}`; var xhr = new XMLHttpRequest(); xhr.open('post', '../../includes/seller.inc.php'); xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhr.onload = function () { if (this.readyState == 4) { console.log(this.responseText); } } xhr.send(params); });```}

When running them i dont get an error but i get a response of my own html code printed to the browser.enter image description here

Download script demo [LINK] [Origin]
Download script demo [LINK 2] [Onedrive] Download script demo [LINK 2] [Google drive]