Php MYSQL中的更改后查询未执行

Php MYSQL中的更改后查询未执行,php,mysql,Php,Mysql,//类别 if(empty($Errormessage)) { if(move_uploaded_file($File_Tmp,"product_images/".$File_Name)) { //To Rename the uploaded file $Random=rand()*1200;

//类别

if(empty($Errormessage))
            {
                    if(move_uploaded_file($File_Tmp,"product_images/".$File_Name))
                    {
                        //To Rename the uploaded file
                        $Random=rand()*1200;
                        $File_New_Name=$Random.".".$File_Extension;
                        rename("product_images/".$File_Name,"product_images/".$File_New_Name);  
                        $Date_Added=date("d-m-Y");
                        $Query="INSERT INTO products (pro_id,product_name,price,details,product_picture,date_added,last_edited,cat_id) VALUES ('','$Product_Name','$Product_Price','$Product_Details','$File_New_Name','$Date_Added','','$Category')";
                        $Result=mysql_query($Query);
                    if($Result)
                        {
                            header ("location: addsuccess.php");
                        }

                    }
            }
cat_id是“我的产品”表中的FK列。。。而且cat_id也是类别表中的主键。。。因为我把这个cat_id设为FK,实际上我复制粘贴了alter table add column FK等的语法。。。它不允许我保存我的记录。。。我通过传递虚拟值直接在我的管理员php上尝试了它。。它正在工作。

尝试:

if($Category=="Null")
        {
            $Errormessage[]="Category should be selected";
        }
NULL而不是“”可能会解决您的问题。另外,$Category现在没有撇号,因为db列cat_id是一个数字而不是字符串。(数字不应使用撇号处理)

(您试图转义一个字符串,但$\u POST['category']是一个数字),因此这不是正确的方法)

应该是这样的:

$Category=mysql_real_escape_string($_POST['category']); 
也改变了:

if (isset($_POST['category'])) {
   $Category = $_POST['category'];
}
else {
   $Category = 0;
}
?>

?>

这就是错误所在。您的cat\u id参考上有错误。检查db约束$类别插入错误。例如,如果cat_id与其他表连接,则无法使用$Category插入该表。

会出现什么错误?我没有收到任何错误。。。正在将图片保存到我的文件夹中..页面刚刚刷新。。。。没有错误您的代码告诉$Errormessage必须为空,并且文件必须正确上传。$Errormessage的值是多少。是空的吗?代码是否真的进入了开始上传的if语句?yes error msg是一个验证错误数组,在drp下拉列表中称为cateogry id和name frm category table。。。。值=$cat\u id。。。现在我使用了$_Post['categry']=$Category。。。我想在products表中保存类别的名称和id…首先检查您的查询以确保这是cat_id错误。这是一个快速的故障排除。分离cat_id和$Category并运行脚本。如果脚本插入正确,则需要在$query之前进行单独的insert category查询,然后使用$category=mysql\u insert\u id()将id传递给$query。我尝试删除cat\u id,但$category仍然不起作用。。它一直运行到移动上传文件等待让我试试。。。。但是我不认为它会起作用:我试着从我的查询中删除$category,它仍然有效…让我检查一下这个$category的输出是什么?(添加echo$Category;在最后一行):(不,它只是刷新页面本身,$Category的输出是什么?$Cat_Id那是什么?$ttttttttt:s我回显了$Category,它说$Cat_Id
$Category=mysql_real_escape_string($_POST['category']); 
if (isset($_POST['category'])) {
   $Category = $_POST['category'];
}
else {
   $Category = 0;
}
  ?>
    <option value="$Cat_Id"><?php echo $Category_Name; ?></option>
  <?php } ?>
  ?>
    <option value="<?php echo $Cat_Id;?>"><?php echo $Category_Name; ?></option>
  <?php } ?>