0

When I submit null in center_id (not an auto increment column) in single quotes it give me the error incorrect integer value for column center_id and when I write only the variable like this

center_id = $center_id 

it gives a mysql error. Please tell me what I am doing wrong with it or suggest something. Below is my query.

Insert into parent_details set center_id='$center_id',name='$name',pin='$pin' 

Thanks in advance.

7
  • NULL is without quotes, also check whether your column has attribute not null in which case it wont accept NULL values. Commented Apr 21, 2014 at 5:02
  • What is data type of center_id? Commented Apr 21, 2014 at 5:02
  • 1
    If center_id is an int datatype, you don't need to put the value in quotes. Commented Apr 21, 2014 at 5:03
  • Could you share the actual php code that you're using and what you're trying to accomplish? Commented Apr 21, 2014 at 5:07
  • Center_id data type is int and allowed as null(default null) Commented Apr 21, 2014 at 5:09

3 Answers 3

2

Numbers and nulls should not be quoted, strings should. Additionally, your syntax for inserting is wrong:

INSERT INTO parent_details (center_id, name, pin) VALUES ($center_id, '$name', $pin) 
Sign up to request clarification or add additional context in comments.

1 Comment

when i not quote it out it gives me the error you have error in your mysql syntax on line 1 near pin................
0

If you're using prepared statements you shouldn't have this problem in the first place:

$stmt = $db->prepare('Insert into parent_details set center_id=:center, name=:name, pin=:pin'); $stmt->execute([ ':center' => null, ':name' => 'foo', ':pin' => 'bar', ]); 

Comments

0

field center_id data type is int but you may inserted string or special characters because of that is giving above error use below code try to insert integer to center_id column

insert into parent_details (center_id,name,pin) VALUES ($center_id, $name, $pin) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.