0

What is the problem

$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'");
Shadow
  • 33,525
  • 10
  • 51
  • 64

1 Answers1

0

If you want to include the value of $newCandidatePosition into the data that you're inserting, you include it as a literal in the SELECT list, not in the list of columns you're inserting into.

$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'");
Barmar
  • 741,623
  • 53
  • 500
  • 612