php - error in SQL syntax with html checkbox value -
surely stupid issue, can not find error.
from form value of checkbox (0 or 1), query generates error. "you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'check)"
<form action="processcategory.php?action=add" method="post" enctype="multipart/form-data" name="frmcategory" id="frmcategory"> <input type="hidden" name="check" value="0" /> <input type="checkbox" name="check" value="1" /> </form>
php
$checkboxvalue = (isset($_post['check'])) ? intval($_post['check']) : 0; // returns 0 or 1 $sql = "insert tbl_category (cat_parent_id, cat_name, cat_description, check) values ($parentid, '$name', '$description', $checkboxvalue)"; $result = dbquery($sql) or die('cannot add category' . mysql_error());
mysql field: check
`check` tinyint(1) not null
check
reserved word , using inside query 1 of column.
you need use backticks `
escape reserved words in mysql:
insert tbl_category (cat_parent_id, cat_name, cat_description, `check`)
Comments
Post a Comment