你好我有mysql的问题; 我想创建一个网络应用来管理收费;在此页面中,用户将创建一个月并添加月份费用 我这里有三个表,表年(ID;年)表月(ID,月,id_year)和表费(ID,名称,描述,值,ID_month) 当用户选择他想要的月份时,他添加费用并点击提交;月份应该添加到表月,同时费用被添加到表费用,问题是我需要月份ID将其添加到表费用,所以我在第一个“多个请求”之后选择它#39;完成然后我尝试通过添加月份ID来更新表费用,但它不起作用,我收到此错误'命令不同步;你现在不能运行这个命令' 这里是代码请帮我找一个解决方法怎么做plz谢谢
//--test POST vars
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//test inputs from functions.php
$month = test_input($_POST['month']);
//year from url GET
$year = 2000;
$sql_year = "SELECT ID FROM year WHERE year = '" . $year . "' ";
$year_result = mysqli_query($conn, $sql_year);
$year_fetch = mysqli_fetch_assoc($year_result);
$year_ID = $year_fetch['ID'];
//check if month already exist
$check_month = "SELECT ID FROM month WHERE month = '" . $month . "' AND year_ID = '" . $year_ID . "'";
$month_result = mysqli_query($conn, $check_month);
if (mysqli_num_rows($month_result) == 1) {
//if it exist do nothing but set error msg
$msgerr = $lang['addmonth-error-monthexist'];
} else {
//insert month and year ID in month table
$sql = "INSERT INTO month (month, year_ID) VALUES ('" . $month . "','" . $year_ID . "');";
//depending on how many charges were set do the test inputs and add to sql db
foreach ($_POST['charge'] as $iq => $val) {
$charge[$iq] = test_input($val);
$description[$iq] = test_input($_POST['description'][$iq]);
$value[$iq] = test_input($_POST['value'][$iq]);
$sql .= "INSERT INTO charges (designation, description, value) VALUES ('" . $charge[$iq] . "','" . $description[$iq] . "','" . $value[$iq] . "');";
}
if ($reslult = mysqli_multi_query($conn, $sql) === TRUE) {
$msgs = $lang['message_succ_datasaved'];
} else {
$msge = $lang['message_errorgen'];
}
//Select the add month's ID
$msql= "SELECT ID FROM month WHERE month = '".$month."' && year_ID = '".$year_ID."' ";
$month_idqu = mysqli_query($conn,$msql);
if (!$month_idqu) {
echo 'MySQL Error: ' . mysqli_error($conn);
exit;
}
$month_id = mysqli_fetch_assoc($month_idqu);
$charge_up = mysqli_query($conn, "UPDATE charges SET month_ID = '".$month_id."' WHERE ID = '".$charge_id."' ");
}//end else if month exist
}//end if request method