I'm just trying to put information from a form into a database. I have form information that is sent to code below. I've been working with this code with no results. It gives me an error only if I don't fill in the required fields. I've checked the connection with the mysql and it seems to be working. Any other ideas?
<html>
<head>
<title>database work</title>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$userid=$_POST['userid'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$organ=$_POST['organ'];
$email=$_POST['email'];
$comments=$_POST['comments'];
if (!$userid || !$fname || !$lname || !$organ || !$comments)
{echo 'You have not entered all the fields, try again';
exit;
}
@ $db=new mysqli('localhost', 'root', 'xxx','ites');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database.';
exit;
}
$query ="insert into user values ('".$userid."','".$fname."','".lname."','".$organ."','".$email."','".$comments."')";
$result = $db->query($query);
if ($result)
echo $db->affected_rows.' information inserted into database.';
$db->close();
?>
</body>
</html>
<html>
<head>
<title>database work</title>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$userid=$_POST['userid'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$organ=$_POST['organ'];
$email=$_POST['email'];
$comments=$_POST['comments'];
if (!$userid || !$fname || !$lname || !$organ || !$comments)
{echo 'You have not entered all the fields, try again';
exit;
}
@ $db=new mysqli('localhost', 'root', 'xxx','ites');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database.';
exit;
}
$query ="insert into user values ('".$userid."','".$fname."','".lname."','".$organ."','".$email."','".$comments."')";
$result = $db->query($query);
if ($result)
echo $db->affected_rows.' information inserted into database.';
$db->close();
?>
</body>
</html>