I am confused as to why my insert statement in entering an incorrect value into mysql.
var_dump($_POST) shows the correct value being passed, which is “1” but the insert statement is inserting it as “0”. The mysql field is ‘varchar (4)’ and can accept a null value. I have tried changing null to no, but still it inerts “0”.
I have posted the var_dump,echoed the $sql statement and the $sql insert code.to show the point. I would be grateful if someone could point out my error. Many thanks
BTW The field in question is ‘size’.
$size = mysqli_real_escape_string($conn, $_POST['size']);
array(9) { ["sub"]=> string(11) "demobox0017" ["company"]=> string(4) "DEMO" ["dept"]=> string(4) "DEMO" ["address"]=> string(47) "22 London Road Charles House London W12 3RT " ["service"]=> string(8) "standard" ["altdate"]=> string(0) "" ["activity"]=> string(14) "New Box Intake" ["destroydate"]=> string(10) "16/12/2027" ["size"]=> string(1) "1" }
echoed $sql
INSERT INTO `act` (service, activity, size, department, company, address, user, destroydate, date, requestdate, item, new) VALUES ('Standard', 'New Box Intake', '0', 'DEMO', 'DEMO', '22 London Road Charles House London W12 3RT ', 'Admin', '2027-12-16', NOW(), NOW(), 'DEMOBOX0017', 1)
$sql = "INSERT INTO `act` (service, activity, size, department, company, address, user, destroydate, date, requestdate, item, new) VALUES ('$service', '$activity', '$size', '$dept', '$company', '$address', '$authorised', '$newdate', NOW(), NOW(), '".strtoupper($items)."', 1)";
mysqli_query($conn, $sql) or die ('Error inserting act box:' . mysqli_error($conn));
html
<select class="chosen-select" data-placeholder="Select a Box Size" id="size" name="size">
<option value=""></option>
<option value="0">Standard</option>
<option value="1">Printout</option>
<option value="2">Other</option>
<option value="3">Transfer</option>
</select>