首先,我知道 php mysql_* 函数已被贬值,但我的主管希望我使用该函数。
在这段代码中,除了以下行之外,一切都运行良好:$insert =
"insert into match (t_id, s_id) values ('$tutor_id', '$student_id')";
使用以下行正确打印数据:
echo "<script>alert('$tutor_id, $student_id')</script>";
但是数据仍然不会进入表“匹配”。我想不通这个问题
任何帮助将不胜感激。
mysql_query($insert);
$run_6 = mysql_query("select tutors.tutor_id, students.student_id
from tutors, students
where tutor_availability = '$student_availability'
AND (tutor_subject_1 = '$student_subject_1'
OR tutor_subject_1 = '$student_subject_2'
OR tutor_subject_2 = '$student_subject_2'
OR tutor_subject_2 = '$student_subject_1')");
while($row = mysql_fetch_row($run_6)) {
$tutor_id = $row[0];
$student_id = $row[1];
echo "<script>alert('$tutor_id, $student_id')</script>";
$insert = "insert into match (t_id, s_id) values ('$tutor_id', '$student_id')";
mysql_query($insert);
}
最佳答案
匹配
是 reserved keyword 。这意味着如果您要命名一个表,则必须将其包含在刻度中:
insert into `match` (t_id, s_id) values ('$tutor_id', '$student_id')
如果您在代码中进行了错误检查和处理,就会引起您的注意。至少在开发过程中检查 mysql_error()
。
关于php - 将数据插入新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22670227/