I have this simple code where I am trying to have 3 fields, first name, last name, and email, tag to mysql database from a website form. When I test the form and hit “register”
the error comes up that “An Error Has Occured. The item was not added.” How can I debug this, as I’m not sure what point the error is coming in?
<html>
<head>
<title> Nomad - New User Registration Results</title>
</head>
<body>
<h1>Nomad - New User Registration Results</h1>
<?php
// create short variable names
$First_Name=$_POST['First_Name'];
$Last_Name=$_POST['Last_Name'];
$Email=$_POST['Email'];
if(!$First_Name || !$Last_Name || !$Email) {
echo "You have not entered all the required details.<br />"
."Please go back and try again.";
exit;
}
@ $db=new mysqli('localhost','nomad_steve','steven','nomad_prod');
if (mysqli_connect_errno()) {
echo "Error: Could not connect to database. Get it together Steve!";
exit;
}
$query = "insert into nomad_prod values
(' " .$First_Name.",' " .$Last_Name."',' ".$Email."')";
$result=$db->query($query);
if ($result) {
echo $db->affected_rows." book inserted into database.";
} else {
echo "An Error Has Occured. The item was not added.";
}
$db->close();
?>
</body>
</html>
Try this may solve your problem
I have checked and got it you have to specify your column name where you have to enter your data.