问题是什么
$id = $_POST['name']; //prevents types of SQL injection
$newCandidatePosition = $_POST['position']; //prevents types of SQL injection
$sql = mysql_query("INSERT INTO tbCandidates(`student_id`,`candidate_name`, `candidate_gender`,`candidate_grade`,`candidate_section`,`candidate_position('$newCandidatePosition'))"." SELECT `id`,`student_name`, `student_gender`,`student_grade`,`candidate_section`"." FROM tbstudent WHERE id='$id'");
答案 0 :(得分:0)
如果要将$newCandidatePosition
的值包含在要插入的数据中,请将其作为文字包含在SELECT
列表中,而不是在要插入的列的列表中成。
$id = mysql_real_escape_string($_POST['name']); //prevents types of SQL injection
$newCandidatePosition = mysql_real_escape_string($_POST['position']); //prevents types of SQL injection
$sql = mysql_query("INSERT INTO tbCandidates(`student_id`,`candidate_name`, `candidate_gender`,`candidate_grade`,`candidate_section`,`candidate_position`)
SELECT `id`,`student_name`, `student_gender`,`student_grade`,`candidate_section`, '$newCandidatePosition'
FROM tbstudent WHERE id='$id'");