0

I do have two check boxes named as Active and Require and i do have a grid as well in which i have to insert the data of this two check boxes.for that i have written the Insert statement as follows:

$myVals=$_POST;     
$fields ="question,active,req,sort_order,dtype";
$myVals["sort_order"]="";
$myVals["dtype"]="";
$sql=makeSQL($myVals,$fields,
    "INSERT INTO s_additional_data(kunnr,$fields)values("."'".$_SESSION['kunnr']."',",

but i am getting an error as Incorrect integer value: '' for column error. suggest me on this.

3
  • 5
    It might be necessary to paste at least your entire query rather than just half of it. Commented Nov 28, 2012 at 13:51
  • is your posted code correct? Commented Nov 28, 2012 at 13:51
  • 9 out of ten times I get that error, it is due to an empty string being handeled as an integer, but as the others say, it is not possible to help you without some more info Commented Nov 28, 2012 at 13:56

3 Answers 3

3

try

 $_POST['active'] = ($_POST['active'] == 'on') ? 1 : 0; 
 $_POST['req]' = ($_POST['req'] == 'on') ? 1 : 0;

 $myVals=$_POST;
 ////
 etc
Sign up to request clarification or add additional context in comments.

3 Comments

welcome to SO, as a generic matter - could you add some explanation to your code?
Hi @Luca, the reason for the previous conditional is because checkbox return "on" if is check, but no return a number.
thanks, my comment was just generic - it is normally better to add some explanation for anyone that might be reading your answer in the future :) you can also edit your own post rather than add it as a comment. Enjoy SO!
0

It is hard to tell without seeing the complete sql statement and a var_dump($_POST), but most likely the problem is that there are non-checked checkboxes.

A checkbox is only sent to the server when it is checked, so if you do not check either Active or Require, you will end up with with a $myVals variable that is incomplete.

To avoid that, you can do for example (for all checkboxes, if they are supposed to be integers...):

$myVals["Active"] = isset($_POST['Active']) ? (int) $_POST['Active'] : 0;
// etc.

Comments

0

You are hard coding sort_order as a blank string:

$myVals["sort_order"]="";

I think this is the problem, I think your sort_order column is an int, so it's trying to put a blank string into the int column, as the error suggests.

Set it to 0 or some other integer:

$myVals["sort_order"] = 0;

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.