$sql = "INSERT INTO placed_req(username,goodsauto,minitruck,largetruck,price,qty) VALUES('$user_check','$ga','$mt','$lt','$r','$qty')";
$result = mysqli_query($con,$sql);
$sql2="SELECT reqid FROM placed_req WHERE username='$user_check' AND price='$r'";
$ret=mysqli_query($con,$sql2);
$sql1 = "INSERT INTO inv_detail (inv_id,p_name,qty,price) VALUES('$ret','$user_check','$qty','$r')"; //i'm getting that error in this line
$result1 = mysqli_query($con,$sql1);
if(isset($result1))
echo "<br></br> Invoice generated successfully";
header("refresh:10,url=placeorders.php");
} else {
echo "<br></br> values not selected";
}
答案 0 :(得分:1)
如果你想将req_id放入插入查询中,你必须正确地获取req_id
$sql2="SELECT reqid FROM placed_req WHERE username='$user_check' AND price='$r'";
$ret=mysqli_query($con,$sql2);
$row = mysqli_fetch_assoc($ret);
/* above instruction fetch record from database*/
$inv_id = $row['reqid'];
然后将$inv_id
放入插入查询语句
$sql1 = "INSERT INTO inv_detail (inv_id,p_name,qty,price) VALUES('$inv_id','$user_check','$qty','$r')"; //i'm getting that error in this line
$result1 = mysqli_query($con,$sql1);
答案 1 :(得分:0)
如果您从
修复查询"SELECT reqid FROM placed_req WHERE username=\'" . $user_check . "\' AND price=\'" . $r . "\'";
要:
$sql1 = "INSERT INTO inv_detail (inv_id,p_name,qty,price) VALUES('$ret','$user_check','$qty','$r')";
并且
$sql1 = "INSERT INTO inv_detail (inv_id,p_name,qty,price) VALUES(\'" . $ret . "\',\'" . $user_check . "\',\'". $qty . "\',\'" . $r . "\')";
ret
您最终可以在查询中使用变量的值。和@pritamakumar说的一样,你必须正确地获取{{1}}