1

I'm trying to save the checkbox value .. I'm doing a enrollment system with a checkbox form. It's function is to know if the student pass the requirement, so I assign it as a boolean type. It must save the value of '1' if the checked and '0' if unchecked.

and the error are:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '')' at line 2

and if I uncheck one of the requirement this is what happen:

Notice: Undefined index: brigada_form in C:\xampp2\htdocs\es\add_newstud.php on line 12
Notice: Undefined index: two_picture in C:\xampp2\htdocs\es\add_newstud.php on line 18

I really need some help. Here is the code..

Sample form: 1 set the value as '1' and the default value in my database is '0'

<input type="checkbox" name="two_picture" id="two_picture" value="1" />

php code add_newstud.php

$requirement_id = $_POST['requirement_id'];     
$enrollment_form = $_POST['enrollment_form'];
$report_card = $_POST['report_card'];
$brigada_form = $_POST['brigada_form'];
$physical_inspection_form= $_POST['physical_inspection_form'];      
$agreement_upon_enrollment = $_POST['agreement_upon_enrollment'];
$nso = $_POST['nso'];
$good_moral = $_POST['good_moral'];
$one_picture = $_POST['one_picture'];       
$two_picture = $_POST['two_picture'];

$insert_req = "INSERT INTO es_req_newstud(requirement_id,enrollment_form,report_card,brigada_form,physical_inspection_form,agreement_upon_enrollment,nso,good_moral,1x1_picture,2x2_picture) `VALUES` ('$requirement_id','$enrollment_form','$report_card','$brigada_form','$physical_inspection_form','$agreement_upon_enrollment','$nso','$good_moral','$one_picture','$two_picture)";
mysql_query($insert_req) or die(mysql_error());
3
  • Hello, At the end of your query you have a missing ' (after picture). -----> ,'$two_picture)" Commented Sep 15, 2015 at 18:13
  • oh thank you.. but there is still an error You have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the right syntax to use near '')' at line 2 i don't know whats wrong.. Commented Sep 15, 2015 at 19:59
  • Why is VALUES wrapped like that? I would suggest just: INSERT INTO es_req_newstud(requirement_id,enrollment_form,report_card,brigada_form,physical_inspection_form,agreement_upon_enrollment,nso,good_moral,1x1_picture,2x2_picture) VALUES ('$requirement_id','$enrollment_form','$report_card','$brigada_form','$physical_inspection_form','$agreement_upon_enrollment','$nso','$good_moral','$one_picture','$two_picture') Commented Sep 15, 2015 at 20:22

1 Answer 1

1

Firstly, MySQL extensions are deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

If you must use MySQL, I would advise:

$insert_req = sprintf("INSERT INTO es_req_newstud (requirement_id,enrollment_form,report_card,brigada_form,physical_inspection_form,agreement_upon_enrollment,nso,good_moral,1x1_picture,2x2_picture) VALUES ('%d','%s','%s','%s','%s','%s','%s','%s','%d','%d');",
    $_POST['requirement_id'],
    mysql_real_escape_string($_POST['enrollment_form']),
    mysql_real_escape_string($_POST['report_card']),
    mysql_real_escape_string($_POST['brigada_form']),
    mysql_real_escape_string($_POST['physical_inspection_form']),
    mysql_real_escape_string($_POST['agreement_upon_enrollment']),
    mysql_real_escape_string($_POST['nso']),
    mysql_real_escape_string($_POST['good_moral']),
    $_POST['one_picture'],
    $_POST['two_picture']
);
mysql_query($insert_req) or die(mysql_error());

This will help ensure that no SQL Injection occurs. Again, I would strongly advise moving to MySQLi or PDO.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.