I have this problem, when i am printing the second parameter from mysqli query it prints out the query to be performed but when i print the first parameter it prints nothing and when I perform the query it produces an error and it cannot insert the data into database. Here's my code:
$Insert_Patient_Data = "INSERT INTO patient_account(P_Password,P_Fname,P_Lname,P_Mname,P_Age,P_Gender,P_Email)
VALUES('$Encrypted_Password', '$Inputted_First_Name', '$Inputted_Last_Name', '$Inputted_Middle_Name', '$Inputted_Age', '$Inputted_Gender', '$Inputted_Email')";
$Patient_Query = mysqli_query($Connection, $Insert_Patient_Data);
if(!$Patient_Query)
echo "<script type = 'text/javascript'> alert('Error: Database Connection error. Please try again Later.') </script>";
else
echo "<script type = 'text/javascript'> alert('Succesfully Registered.') </script>";
Question: Why it becomes a null? and what happens? and what is the solution on it? There are some queries on this page accessing the same table but they had no problem.
PS i checked the table name and column names from the database and they are all okay. I also included the System_Connector.php (Where the connection to database and the variable $connection is declared).
var_dump($Connection) will show you have a mysqli object, you cant echo objects!
Anyway, call mysqli_error($Connection)
if it fails http://php.net/manual/en/mysqli.error.php
$Patient_Query = mysqli_query($Connection, $Insert_Patient_Data) or die(mysqli_error($Connection));
Or even:
if(!$Patient_Query = mysqli_query($Connection, $Insert_Patient_Data);)
//fail
else
// pass
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.