gpt4 book ai didi

php - 检索要插入的数据以及插入输入的数据

转载 作者:行者123 更新时间:2023-11-29 18:25:12 26 4
gpt4 key购买 nike

问题是什么

$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'");

最佳答案

如果要将 $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'");

关于php - 检索要插入的数据以及插入输入的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46250683/

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