mercredi 16 mars 2016

Checkboxes don't pass on value to DB

I have created a contact form on my website using php and some of the values, more specifically the ones that have a checkbox-type input, are not send to my DB. I think there must be something wrong with the way I use the checkboxes or something. Upon submitting a form I get several notices like such:

Notice: Undefined index: ironing in /Applications/XAMPP/xamppfiles/htdocs/wordpress/demo.php on line 79

Notice: Undefined variable: POST in /Applications/XAMPP/xamppfiles/htdocs/wordpress/demo.php on line 94

The rest of the code seems to work fine and the data is loaded into my DB.

Here is some of my code in the demo-form.php file that I think is wrong:

<h4>i) Cleaningservice:</h4>
     <p>Experience (in years): <input type="number" name="cleanExpInYears"/> </p>
     <p>Skills: <br>
       <input type="checkbox" name="basic" value="yes"> Basic cleaning<br>
       <input type="checkbox" name="kitchen" value="yes"> Kitchen tools<br>
       <input type="checkbox" name="laundry" value="yes"> Laundry<br>
       <input type="checkbox" name="ironing" value="yes"> Ironing<br>
       <input type="checkbox" name="window" value="yes"> Windows<br>
     <p> Please tell us about other skills: <input type="text" name="other_clean"/> </p>
     </p>

And here is the corresponding demo.php file that connects to the DB and stores the data there:

/* Cleaningservice data is gathered... */

$clean_value1 = $_POST['cleanExpInYears'];
$clean_value2 = $_POST['basic'];
$clean_value3 = $_POST['kitchen'];
$clean_value4 = $_POST['laundry'];
$clean_value5 = $_POST['ironing'];
$clean_value6 = $_POST['window'];
$clean_value7 = $_POST['other_clean'];

/* ...and inserted into the table cleaningservice */

$sql = "INSERT INTO cleaningservice (applicant_id, cleanExpInYears, basic, kitchen, laundry, ironing, window, other)
        VALUES (LAST_INSERT_ID(),'$clean_value1', '$clean_value2', '$clean_value3', '$clean_value4', '$clean_value5', '$clean_value6', '$clean_value7')";

if (!mysql_query($sql)) {
 die('Error: ' . mysql_error());
}

What am I missing here ?? Thanks in advance




Aucun commentaire:

Enregistrer un commentaire