0

i am trying tomake a form to add data to my data base and im getting a error

"Could not enter data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('s','d','f','g','h')' at line 1"

here is the code im using

<html>
<head>
<title>Add New Record in MySQL Database</title>
</head>
<body>
<?php
if(isset($_POST['add']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

if(! get_magic_quotes_gpc() )
{
   $make = addslashes ($_POST['make']);
   $model = addslashes ($_POST['model']);
   $value = addslashes ($_POST['value']);
   $bcosts = addslashes ($_POST['bcosts']);
}
else
{
   $make = $_POST['make'];
   $model = $_POST['model'];
   $value = $_POST['value'];
   $bcosts = $_POST['bcosts'];
}
$rcosts = $_POST['rcosts'];

$sql="INSERT INTO referb (make,model,rcosts,bcosts,value,) VALUES ('$make','$model','$rcosts','$bcosts','$value')";  

mysql_select_db('ely');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">make</td>
<td><input name="make" type="text" id="make"></td>
</tr>
<tr>
<td width="100">model</td>
<td><input name="model" type="text" id="model"></td>
</tr>
<tr>
<td width="100">repair costs</td>
<td><input name="rcosts" type="text" id="rcosts"></td>
</tr>
<tr>
<td width="100">paid costs</td>
<td><input name="bcosts" type="text" id="bcosts"></td>
</tr>
<tr>
<td width="100">value</td>
<td><input name="value" type="text" id="value"></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">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>

i am very novice hence why i am asking lol dont worry this will never be a live site:)

Rick Skeels
  • 513
  • 1
  • 11
  • 30
  • Just to make sure you know it: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Nabil Kadimi Aug 17 '13 at 01:12
  • thanks for the heads up- i am extremly novice and trying to get to grips with it i prefer a hands on approach. and there seems to be more samples and tutorials regarding this way then the new ways. is there any easy to follow tutorials in the way you mention? – Rick Skeels Aug 17 '13 at 01:17

1 Answers1

1

Replace value, with value here:

$sql="INSERT INTO referb (make,model,rcosts,bcosts,value,) VALUES ('$make','$model','$rcosts','$bcosts','$value')";  

So it becomes:

$sql="INSERT INTO referb (make,model,rcosts,bcosts,value) VALUES ('$make','$model','$rcosts','$bcosts','$value')";  
Nabil Kadimi
  • 10,078
  • 2
  • 51
  • 58