gpt4 book ai didi

php - 多个查询在一个php文件中使用前一个查询的结果集

转载 作者:行者123 更新时间:2023-11-29 14:35:11 28 4
gpt4 key购买 nike

我正在尝试使用从 MySQL 查询收到的值,然后执行插入操作,但它不起作用。我收到语法错误,但插入查询是正确的。

选择查询返回我正在检查的金额,然后程序应该执行插入查询。

    <?php
require 'header.php';

$resID = mysql_real_escape_string($_POST['resID']);
$materialen_id = mysql_real_escape_string($_POST['materialen_id']);
$aantal = mysql_real_escape_string($_POST['aantal']);
$effectief_gebruikt = mysql_real_escape_string($_POST['effectief_gebruikt']);
$opmerking = mysql_real_escape_string($_POST['opmerking']);
//$datum_van = date('d-m-Y', $_POST['datum_van']);
//$datum_tot = date('d-m-Y', $_POST['datum_tot']);
$datum_van = $_POST['datum_van'];
$datum_tot = $_POST['datum_tot'];


$sql = "SELECT `aantal_beschikbaar`
FROM `materialen`
WHERE `id` = $materialen_id";

$result = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_array($result))
{
$tot = $row['aantal_beschikbaar'];
echo 'totaal: ' . $tot;
}



$sql2 = "SELECT `aantal` FROM `materialen_per_reservatie`
WHERE `materialen_id` = $materialen_id";
$result2 = mysql_query($sql2) or die(mysql_error());

while ($row = mysql_fetch_array($result2))
{
//$aant = $row['aantal'];
//echo $aant
echo $row['aantal'];
}

$besch = ($tot - $aant);
echo 'beschikbaar: ' . $besch;



/*$sql3 = "SELECT * FROM `materialen_per_reservatie`
WHERE `reservaties_id` = $resID
AND `materialen_id` = $materialen_id";
$result3 = mysql_query($sql3) or die(mysql_error());*/

if($besch > $aantal){



$string2 = "INSERT INTO `materialen_per_reservatie`(`reservaties_id`, `materialen_id`, `aantal`, `effectief_gebruikt`, `opmerking`, `datum_van`, `datum_tot`) VALUES ($resID, $materialen_id, $aantal, $effectief_gebruikt, '$opmerking', '$datum_van', '$datum_tot')";
mysql_query($string2) or die(mysql_error());


}

require 'footer.php';
?>

最佳答案

假设错误仅出现在插入查询上...

您的插入查询缺少所需的空格:

INSERT INTO `materialen_per_reservatie` (`reservaties_id`, `materialen_id`, `aantal`, `effectief_gebruikt`, `opmerking`, `datum_van`, `datum_tot`) VALUES ($resID, $materialen_id, $aantal, $effectief_gebruikt, '$opmerking', '$datum_van', '$datum_tot')

materialen_per_reservatie后面添加一个空格。我不确定您是否需要所有报价。

INSERT INTO materialen_per_reservatie (reservaties_id, materialen_id, aantal, effectief_gebruikt, opmerking, datum_van, datum_tot) VALUES ($resID, $materialen_id, $aantal, $effectief_gebruikt, '$opmerking', '$datum_van', '$datum_tot')

关于php - 多个查询在一个php文件中使用前一个查询的结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9212035/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com