I am creating a CRUD page. I've been able to insert data into my database, with the following code:
$query="INSERT INTO user(USER_ID, PASSWORD, FIRST_NAME, LAST_NAME, CONTACT_NO, SHIPPING_ADDRESS, BILLING_ADDRESS, EMAIL) VALUES('$user_id', '$password', '$first_name', '$last_name', '$contact_no', '$shipping_address', '$billing_address', '$email')";
if(mysqli_query($con, $query))
{
echo "<center><font color=#FF0000>Record Inserted!</font></center><br>";
}
else{printf("error: %s\n", mysqli_error($con));}
}
}
however, i am unable to delete nor edit the data as the "Unknown column in 'where clause' " error will appear. i've tried finding for solutions on google but they did not work. can someone help to see if there are any errors in my code?
The following codes are for editting data in the database:
$query="UPDATE user SET USER_ID='$user_id' , PASSWORD='$password', FIRST_NAME='$first_name', LAST_NAME='$last_name', CONTACT_NO='$contact_no', SHIPPING_ADDRESS='$shipping_address', BILLING_ADDRESS='$billing_address', EMAIL='$email' WHERE USER_ID=".$_POST['user_id'];
if(mysqli_query($con, $query))
{
echo "<center><font color=#FF0000>Record Updated!</font></center><br>";
}
else{printf("error: %s\n", mysqli_error($con));}
}
The following codes are for deleting data in the database:
if(isset($_GET['operation'])){
if($_GET['operation']=="delete")
{
$query="DELETE FROM user WHERE USER_ID=".$_GET['user_id'];
if(mysqli_query($con, $query))
{
echo "<center><font color=#FF0000>Record Deleted!</font></center><br>";
}
else{printf("error: %s\n", mysqli_error($con));}
}
}