2017-09-16 13 views
0

を挿入しても問題挿入するデータを取得し、また、入力されたデータ

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

これは次のようなものです: 'candidate_position( '$ newCandidatePosition')'? – Shadow

+0

はユーザの入力から来た –

+0

私はまた、データベースの入力をユーザの入力にしたいが、それは挿入しない。( –

答えて

0

は何ですか、あなたは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'"); 
+0

)。そんなに :) –

関連する問題