Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code question

Status
Not open for further replies.

janet24

Technical User
Jul 22, 2003
161
US
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>
 
This is a PHP question, you need to ask in the PHP forum. Use the search box at the top of the page to find the PHP forum.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top