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");
}
}
}
//类别
<td><select name="category" size="1" id="select">
<option value="Null">Select Category</option>
<?php
$Select=mysql_query("SELECT * FROM category");
while ($Row=mysql_fetch_array($Select))
{
$Cat_Id=$Row['cat_id'];
$Category_Name=$Row['category_name'];
?>
<option value="$Cat_Id"><?php echo $Category_Name; ?></option>
<?php } ?>
</select></td>
//验证
if($Category=="Null")
{
$Errormessage[]="Category should be selected";
}
cat_id 是我的产品表中的 FK 列...而且 cat_id 是类别表中的主键...因为我将此 cat_id 设为 FK 实际上我复制粘贴了 alter table 添加列 fk 等的语法等...它不是让我保存我的记录......我通过传递虚拟值直接在我的管理员上尝试了它......它正在工作。