php - Data type isnt well received by the database -
so big idea want insert oracle database value through input tag number type. problem when input value > 0, works fine. when left if unfilled, error appears,
warning: oci_execute(): ora-00936: missing expression in c:\xampp\htdocs\weltesinformationcenter\content\fabrication\update\fabricationqc\processexceededqcqty.php on line 76
so here input tag:
echo "<td><input name='datamarkingqc' id='datamarkingqc' type='number' min='0' max='$availablemarkingqc' width='5' value='0'></td>";
and processing method this,
$datamarkingqc = intval($_post['datamarkingqc']); if ($datamarkingqc == 0){ $markingqcuser = ""; $markingqcdate = ''; } else { $markingqcuser = $username; $markingqcdate = 'sysdate';} $updateqchistsql = "insert fabrication_qc_hist (marking_qc, marking_qc_date, marking_qc_sign) values ($datamarkingqc, $markingqcdate, '$markingqcuser')";
and var_dump
this
["datamarkingqc"]=> string(1) "0"
so problem is, when submit 0 value in input tag, error appears. data type marking_qc
int.
this code. reformatted here readability. clean formatting readability makes easier debug stuff this:
$datamarkingqc = intval($_post['datamarkingqc']); if ($datamarkingqc == 0) { $markingqcuser = ""; $markingqcdate = ''; } else { $markingqcuser = $username; $markingqcdate = 'sysdate'; } $updateqchistsql = "insert fabrication_qc_hist (marking_qc, marking_qc_date, marking_qc_sign)" . " values ($datamarkingqc, $markingqcdate, '$markingqcuser')" ;
maybe work better:
$datamarkingqc = intval($_post['datamarkingqc']); $markingqcuser = $datamarkingqc == 0 ? null : $username; $markingqcdate = $datamarkingqc == 0 ? null : 'sysdate'; $updateqchistsql = "insert fabrication_qc_hist (marking_qc, marking_qc_date, marking_qc_sign) values ('$datamarkingqc', '$markingqcdate', '$markingqcuser')";
i believe issue lack of single quotes '
around $datamarkingqc
, $markingqcdate
. simplified logic setting $markingqcuser
& $markingqcdate
using ternary logic , setting null
value instead of empty string.
Comments
Post a Comment