[英]Unable to execute mysql query correctly
New to coding . 编码新手。 tried to create a database that stores details for an advertisement .
试图创建一个存储广告详细信息的数据库。 the php works fine till the end .
PHP可以正常工作到最后。 but the output always shows not inserted .
但是输出始终显示未插入。 could someone please help me out ??
有人可以帮我吗?? the form and php are given here .
形式和PHP在这里给出。
<html> <body> <form action="basic.php" method="post"> Name: <input type="text" name="adtitle"></input><br> Name: <input type="text" name="sellersname"></input><br> Name: <input type="text" name="email"></input><br> Name: <input type="text" name="description"></input><br> Name: <input type="text" name="noo"></input><br> Name: <input type="text" name="base"></input><br> Name: <input type="text" name="cutoff"></input><br> <input type="submit"></input> </form> </body> </html>
<?php $serverName = "127.0.0.1"; $userName = "root"; $password = ""; $database = "demo"; $con = mysqli_connect($serverName, $userName, $password, $database); if(!$con) {echo 'not connected';} if(!mysqli_select_db($con,'demo')) {echo'db not selected'; } $Title = $_POST['adtitle']; $Sname= $_POST['sellersname']; $email = $_POST['email']; $Description = $_POST['description']; $Mobileno = $_POST['noo']; $Base = $_POST['base']; $Cutoff = $_POST['cutoff']; $sql = "INSERT INTO advert (Title,Seller name,email,Description,Number,Base,Cutoff)VALUES('$Title','$Sname','$email','$Description','$Mobileno','$Base','$Cutoff')"; if(!mysqli_query($con,$sql)) {echo'not inserted';} else {echo'innserted';} ?>
You have a field, seller name
, which has a whitespace in it. 您有一个字段,
seller name
,其中有一个空格。
You must quote it in backticks: 您必须在反引号中引用它:
Change it from: 更改为:
"INSERT INTO advert (Title,Seller name,email,Description,Number,Base,Cutoff) VALUES ('$Title','$Sname','$email','$Description','$Mobileno','$Base','$Cutoff')"
to: 至:
"INSERT INTO advert (Title,`Seller name`,email,Description,Number,Base,Cutoff)VALUES('$Title','$Sname','$email','$Description','$Mobileno','$Base','$Cutoff')"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.