[英]How to capture primary key from drop down and insert as foreign key of another table?
Please help i commented off some stuff for testing purposes but nothing works 请帮助我评论掉一些东西用于测试目的,但没有任何效果
<?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");
//}
?>
You definietly need to learn how to debug. 您绝对需要学习如何调试。 First, comment out the
Header('Location ...');
首先,注释掉
Header('Location ...');
row, to catch errors. 行,以捕获错误。
add error_reporting(E_ALL);
添加
error_reporting(E_ALL);
and display_errors(1);
和
display_errors(1);
at top of your file, to see any errors. 在文件顶部,以查看所有错误。
Let's var_dump($_POST)
to see, is all the variables are correct. 让我们用
var_dump($_POST)
看看,是否所有变量都是正确的。
Do a date validation, if you are want correct dates. 如果您想要正确的日期,请进行日期验证。
Dump your query, and try to run it in sql directly. 转储您的查询,并尝试直接在sql中运行它。
DO NOT use mysql functions because they are deprecated. 不要使用mysql函数,因为它们已被弃用。 Use mysqli or PDO instead.
改用mysqli或PDO。
Escape your data , to avoid sql injections! 转义数据 ,以避免sql注入!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.