i have been trying to make an ajax call to run a php script but it refuses to do so even though it did work a few days ago. ajax function:
function passDownToPhp(mystring1, mystring2)
{
$.ajax
({
url:"addUserHandling.php",
type: "POST",
cache: false,
data: {username: mystring1, password: mystring2},
dataType: 'json',
success: function(data)
{
alert(data);
}
});
}
And here is the php script EDIT(quotation problem, script should work now):
<?php
include_once "conf.php";
$myusername =$_POST['username'];
$mypassword =$_POST['password'];
$query = "INSERT INTO users (username, password) VALUES ('$myusername', '$mypassword')";
mysqli_query($conn,$query);
$user_id= mysqli_insert_id($conn);
$query = "INSERT INTO profile (username,password,email,user_id) VALUES ('lala','lala','lala','$user_id')";
mysqli_query($conn,$query);
//Redirect('profile.php');
if ($conn->query($query) === TRUE) {
echo '<script>alert("ok")</script>';
echo "New record created successfully";
} else {
//echo "Error: " . $query . "<br>" . $conn->error;
echo '<script>alert("sql problem")</script>';
}
mysqli_close($conn);
?>
The debugging processes i have already follown is sending an alert right before i call the ajax function witch works perfectly fine, the conf.php file IS working since when i log on into the site(session based) i can communicate with my db, and have tried different browsers/flushed cache to no avail. The changes i have made to the site prior to the problem's occurance are : a) connecting the user_id Primary key (auto_incriment) from users table with a secondary key in the profile table b) after i noticed the problem i added the second query in my php file.