I have an ajax inquiry using input values to concatenate a URL string for verification from a .php file as follows:
$.ajax({
url: 'nameCheck.php?name=Bob&pin=2112',
success: function (response) {
console.log(response);
success=(response.name);
alert(success);
}
});
The .php file checks a database for a row with matching values thus:
$name=$_GET['name'];
$pin=$_GET['pin'];
header('Content-type:application/javascript');
$messages = array(
"name"=>$name,
"pin"=>$pin
);
$messages = json_encode($messages);
$result = $conn->query("SELECT id FROM clients WHERE name = '$name' AND pin = '$pin'");
if ($result->num_rows == 0) {
// row not found, do stuff...
echo "Access declined. Name or Pin mismatch for ".$name;
} else {
// row found, do other stuff...
header('Content-type: application/json');
echo json_encode(["name" => $messages]);
exit;
}
When the value is returned to the file with the javascript code it looks like this:
{"name":"Bob","pin":"2112"}
My intent is to redirect to another page using the verified input string, but the result certainly won’t work in a URL string. I need to replace characters in this string so that it looks like this:
name=Bob&pin=2112
After this has been accomplished I can concatenate strings to the actual URL the code will redirect to. Since it’s a local file, the string will only need to be:
verifyInput.php?name=Bob&pin=2112
Any help would be appreciated.
