如何修复以下错误?我认为问题出在我的SQL查询的INSERT INTO
部分。
您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在
附近使用正确的语法
<?php
if (isset($_POST['submitted'])){
include('../mysqli_connect.php');
if (isset($_POST['$pn, $pc,$ps,$pd']));
if(!empty($_POST['product_name'])){
echo'<p> Successful entry.</p>';
$pn = mysqli_real_escape_string ($dbc, trim($_POST['product_name']));
$pn=$_POST['product_name'];
echo "You chose:".$pn."<br>";}
else{
echo '<p>You forgot to enter the product name.</p>';}
if(!empty($_POST['product_category'])){
echo'<p> Successful entry.</p>';
$pc = mysqli_real_escape_string ($dbc, trim($_POST['product_category']));
$pc=$_POST['product_category'];
echo "You chose:".$pc."<br>";}
else{
echo '<p>You forgot to enter the product category.</p>';}
if(!empty($_POST['product_supplier'])){
echo'<p> Successful entry.</p>';
$ps = mysqli_real_escape_string ($dbc, trim($_POST['product_supplier']));
$ps=$_POST['product_supplier'];
echo "You chose:".$ps."<br>";}
else{
echo '<p>You forgot to enter the product category.</p>';}
if(!empty($_POST['product_description'])){
echo'<p>Successful entry.</p>';
$pd=mysqli_real_escape_string($dbc, trim($_POST['product_description']));
$pd=$_POST['product_description'];
echo"You chose:".$pd."<br>";}
else{
echo'<p>You forgot to enter the product_description.</p>';}
//query: Insert into database
$query = "INSERT INTO `products_catalog` (product_name, product_category, product_supplier, product_description) VALUES ('$pn', '$pc', '$ps','$pd')";
$r=@mysqli_query ($dbc,$query);
if($r){
echo"<h2> You entered the product name:".$pn."</h2>";
echo"<h2>You entered the product category:".$pc."</h2>";
echo"<h2>You entered the product supplier:".$ps."</h2>";
echo"<h2>You entered the product description:".$pd."</h2>";}
else{
echo'<h1>System Error</h1>
<p>The product name, category, supplier and description could not be entered. We apologize for any inconvenience. Please try again. If error continues, please contact tech support.</p>';
//Debugging message:
echo '<p>'.mysqli_error($dbc).'<br/><br/> Query:'.$query.'</p>';}
//End of if($r) IF.
mysqli_close($dbc); }
?>
答案 0 :(得分:1)
$query = "INSERT INTO products_catalog (product_name, product_category, product_supplier, product_description) VALUES ('".$pn."', '".$pc."', '".$ps."','".$pd."')";
它可能会修复错误。
:)
答案 1 :(得分:0)
喜欢这个
<?php
if (isset($_POST['submitted'])){
include('../mysqli_connect.php');
if (isset($_POST['$pn, $pc,$ps,$pd']));
if(!empty($_POST['product_name'])){
echo'<p> Successful entry.</p>';
$pn = mysqli_real_escape_string ($dbc, trim($_POST['product_name']));
//$pn=$_POST['product_name']; // THIS LINE NOT REQUIRED
echo "You chose:".$pn."<br>";}
else{
echo '<p>You forgot to enter the product name.</p>';}
if(!empty($_POST['product_category'])){
echo'<p> Successful entry.</p>';
$pc = mysqli_real_escape_string ($dbc, trim($_POST['product_category']));
//$pc=$_POST['product_category']; // THIS LINE NOT REQUIRED
echo "You chose:".$pc."<br>";}
else{
echo '<p>You forgot to enter the product category.</p>';}
if(!empty($_POST['product_supplier'])){
echo'<p> Successful entry.</p>';
$ps = mysqli_real_escape_string ($dbc, trim($_POST['product_supplier']));
//$ps=$_POST['product_supplier']; // THIS LINE NOT REQUIRED
echo "You chose:".$ps."<br>";}
else{
echo '<p>You forgot to enter the product category.</p>';}
if(!empty($_POST['product_description'])){
echo'<p>Successful entry.</p>';
$pd=mysqli_real_escape_string($dbc, trim($_POST['product_description']));
//$pd=$_POST['product_description']; // THIS LINE NOT REQUIRED
echo"You chose:".$pd."<br>";}
else{
echo'<p>You forgot to enter the product_description.</p>';}
//query: Insert into database
$query = "INSERT INTO `products_catalog` (product_name, product_category, product_supplier, product_description) VALUES ('$pn', '$pc', '$ps','$pd')";
$r=@mysqli_query ($dbc,$query);
if($r){
echo"<h2> You entered the product name:".$pn."</h2>";
echo"<h2>You entered the product category:".$pc."</h2>";
echo"<h2>You entered the product supplier:".$ps."</h2>";
echo"<h2>You entered the product description:".$pd."</h2>";}
else{
echo'<h1>System Error</h1>
<p>The product name, category, supplier and description could not be entered. We apologize for any inconvenience. Please try again. If error continues, please contact tech support.</p>';
//Debugging message:
echo '<p>'.mysqli_error($dbc).'<br/><br/> Query:'.$query.'</p>';}
//End of if($r) IF.
mysqli_close($dbc); }
?>