This question already has an answer here:
I am getting this error when I try to input data into my form:
"Error: 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 'Order (Name, Address, Credit_card_number, Product_id, //Delivery_method) VALUES ' at line 1"
I have checked the database name, table name and attribute names over and over and I cannot find the problem.
This is my form for adding to the database:
<html>
<body>
<form action="insert.php" method="post">
<p>Name:
<input type="text" name="name">
</p>
<p>Address:
<input type="text" name="address">
</p>
<p>Credit Card Number:
<input type="text" name="credit_card_number">
</p>
<p>Product Order ID:
<input type="text" name="product_id">
</p>
<p>Delivery Method:
<input type="text" name="delivery_method">
</p>
<p>
<input type="submit">
</p>
</form>
</body>
</html>
This is my insert.php
file:
<?php
$con=mysqli_connect("localhost","root","","order_page");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO Order (Name, Address, Credit_card_number, Product_id, Delivery_method)
VALUES
('$_POST[name]','$_POST[address]','$_POST[credit_card_number]','$_POST[product_id]','$_POST[delivery_method]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
</div>