Jump to content

[SOLVED] Grr... form won't submit data to mysql...


sr20rps13

Recommended Posts

<html>
<head>
<title>Add new customer info.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if(isset($_POST['add']))
{
include 'mysql_config.php';
include 'mysql_connect.php';

$First_name = $_POST['first_name'];
$Last_name = $_POST['last_name'];
$Address = $_POST['address'];
$Phone_number = $_POST['phone_number'];
$Email = $_POST['email'];

$query = "INSERT INTO customr_data
(first_name, last_name, address, phone_number, email)
values
(FIRST_NAME ('$First_name'), LAST_NAME ('$Last_name'), ADDRESS ('$Address'), PHONE_NUMBER ('$Phone_number'), EMAIL ('$Email')";
mysql_query($query) or die('mysql_error');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

include 'mysql_close.php';
echo "New customer added";
}
else
{
?>

<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr> 
<td width="100">First name</td>
<td><input name="first_name" type="text" id="first_name"></td>
</tr>
<tr> 
<td width="100">Last name</td>
<td><input name="last_name" type="text" id="last_name"></td>
</tr>
<tr> 
<td width="100">Address</td>
<td><input name="address" type="text" id="address"></td>
</tr>
<tr> 
<td width="100">Phone Number</td>
<td><input name="phone_number" type="text" id="phone_number"></td>
</tr>
<tr> 
<td width="100">Email</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr> 
<td width="100"> </td>
<td> </td>
</tr>
<tr> 
<td width="100"> </td>
<td><input name="add" type="submit" id="add" value="Add customer"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>

 

Can someone tell me how I can make it so that it displays the mysql error message rather than mysql_error. Also, could someone exam my code and tell me where I went wrong?

hey!

 

the one line answer: instead of having die('mysql_error'), change that to die(mysql_error())

 

That should print out the error message or you could do this, so that the page doesn't look incomplete in case of error:

mysql_quer(...) or $error = mysql_error();

and in the next line,

if (isset($error))

{

  skip other lines

}

and "nicely display error message", so that the page doesn't look incomplete in case of error.

Yes, you arent writing the SQL correctly.

Should be:

$query = "INSERT INTO customr_data
(first_name, last_name, address, phone_number, email)
values
($First_name, $Last_name,$Address,$Phone_number, $Email)";

 

Remember that you will probably need quotes around your text (varchar in your database) values:

 

('$First_name', '$Last_name','$Address','$Phone_number', '$Email')";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.