This question already has an answer here:
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 'table(name,email,pass,price) VALUES('abhi','abhi@abc.com','213123','67')' at line 1.
Here abhi is the value for name.abhi@abc.com is the value for email.213123 is value for pass.67 is the value for price.These values are sent to insert.php fron form.php.The error is in insert.php in the insert query which seems to be all right.So plz guys help me.
there are two files.
1.form.php
<html>
<head><title>Form</title></head>
<body>
<?php
echo '<form method="post" action="insert.php">
<label>Name:</label>
<input type="text" name="name" />
<label>Email:</label>
<input type="text" name="email" />
<label>Password:</label>
<input type="password" name="pass" />
<label>Price:</label>
<input type="text" name="price" />
<input type="submit" name="Submit" value="Submit"/>
</form>'
?>
</body>
</html>
Second file is insert .php
<?php
$con=mysqli_connect('localhost','root','','product') ;
if(mysqli_connect_errno())
{
echo "Failed to connect to mysql".mysqli_connect_error();
}
$name=$_POST['name'];
$email=$_POST['email'];
$pass=$_POST['pass'];
$price=$_POST['price'];
$query = "INSERT INTO table(name,email,pass,price) VALUES('$name','$email','$pass','$price')";
if(!mysqli_query($con,$query))
{
die('Error: '.mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
</div>
Table is not a valid name for a table (because it's a reserved name). You could either (preferably) rename your table to another name OR use INSERT INTO table
with the `-signs arround table.
Table is a reserved word. You cannot use reserved word as name table, ever.