Php 如何从下拉列表中捕获主键并作为另一个表的外键插入?
请帮我把一些东西注释掉以便测试,但没有任何效果Php 如何从下拉列表中捕获主键并作为另一个表的外键插入?,php,mysql,Php,Mysql,请帮我把一些东西注释掉以便测试,但没有任何效果 <?php //retrieve the data sent in the POST request $yourDateOrdered =$_POST["DateOrdered"]; $yourDueDate = $_POST["DueDate"]; if(isset($_POST["CompanyName"])){$yourCompanyName = $_POST["Comp
<?php
//retrieve the data sent in the POST request
$yourDateOrdered =$_POST["DateOrdered"];
$yourDueDate = $_POST["DueDate"];
if(isset($_POST["CompanyName"])){$yourCompanyName = $_POST["CompanyName"];}
//Validate the fields
if ($yourDateOrdered=="" || $yourDateOrdered==null){
$err= $err."Please enter the date the purchase order was made<br>";
}
if ($yourDueDate=="" || $yourDueDate==null){
$err= $err. "Please enter a date when the item is required<br>";
}
//if ($yourCompanyName=="" || $yourCompanyName==null){
//$err= $err."Please enter the customer name<br>";
//}
//Connect to the server and select database
include("dbConnection.php");
//define sql query to execute on the database
$Query1="INSERT INTO orders(CompanyName, DateOrdered, DueDate)
VALUES ('$yourCompanyName','$yourDateOrdered', '$yourDueDate')";
//execute query
//$result = mysql_query($Query1);
//echo("The following order has been added");
//result of the action stored in $Result
$Result = mysql_query($Query1);
if($Result){
echo 'Order entered';
echo Header ("Location:orderformitem.php");
}
//Close the connection
mysql_close($con);
//Check if query executed successfully and forward the user to an appropriate location
//if($queryResult){
//echo "Order save <br>";
//Header ("Location:../PHP/orderformitem.php");
//}
?>
您确实需要学习如何调试。首先,注释掉标题“Location…”;行,以捕获错误
添加错误报告全部;和显示错误1;在文件顶部,查看任何错误
让我们看看var_dump$_POST是否所有变量都正确
如果您想要正确的日期,请执行日期验证
转储查询,并尝试直接在sql中运行它
不要使用mysql函数,因为它们已被弃用。改用mysqli或PDO
转义您的数据,以避免sql注入
您是否考虑过取消对您评论的内容的评论以使其恢复工作状态?我不明白这个问题和测试目的之间的联系?它一直告诉我我的yourCompanyName是一个未定义的变量