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.
这里abhi是name.abhi @ abc.com的值是email.213123的值是pass.67的值是price的值。这些值被发送到insert.php fron form.php。错误插入查询中的insert.php似乎没问题。所以PLZ伙伴们帮助我。
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);
?>
答案 0 :(得分:0)
表不是表的有效名称(因为它是保留名称)。您可以(最好)将表重命名为另一个名称,或者使用INSERT INTO table
和`-signs arround表。
答案 1 :(得分:0)
表格是reserved word。您不能使用保留字作为名称表。