查询始终输出Probmlem

查询始终输出Probmlem

问题描述:

有谁知道在此查询的问题是什么,每次我往里面outouts脚本的形式“问题!”查询始终输出Probmlem

if(isset($_POST['submit'])){ 
//getting the text data from the fields 
$title = $_POST['title']; 
$cat= $_POST['cat']; 
$desc = $_POST['desc']; 
$qty = $_POST['qty']; 
$price = $_POST['price']; 
$status = $_POST['status']; 



//getting the image from the field 
$image = $_FILES['image']['name']; 
$image_tmp = $_FILES['image']['tmp_name']; 

move_uploaded_file($image_tmp,"images/drinks/$image"); 


$insert_product = "insert into drinks (title,cat,image,desc,qty,price,status) values ('$title','$cat','$image','$desc','$qty','$price','$status')"; 

$insert_pro = mysqli_query($con, $insert_product); 

if($insert_pro){ 

echo "<script>alert('Drink Has been inserted!')</script>"; 
echo "<script>window.open('index.php?viewdrink','_self')</script>"; 

} 
else{ 
    echo "<script>alert('Problem!')</script>"; 
} 
} 

如何改进此代码使其工作。

+0

你知道如何检查真正的错误?你有一个,一个重要的。 –

+0

我不知道,var_dump() –

+0

什么是'$ con'? –

DESC是一个MySQL的保留字,它必须被包裹在蜱,如果你想继续使用该列的名字。

$insert_product = "insert into drinks (title,cat,image,`desc`,qty,price,status)...."; 

已经查询(在else{...})使用mysqli_error($con),就已经暗示了语法错误。

你也开到一个SQL注入。使用准备好的语句。

如果还是失败,请确保没有插入字符会导致注射和所有阵列包含价值。无论如何,你应该转义所有插入数据库的值。

使用PHP的错误报告:

+0

谢谢老兄它帮助 –

+0

@SaqibMalik不客气。 –