Passing NULL from PHP to MySQL for auto increment -


so have database setup in mysql 3 columns. first column 'idnum' auto increments users id numbers. second , third first , last names respectfully. problem when go send the names db via query string in php file, couple different errors back...

when send query:

$sql = "insert namesdb values('null', 'firstname', 'lastname')"; $result = $db->query($sql); 

i error: "incorrect integer value: 'null' column 'idnum' @ row 1." because column 1 int type.

but when send query:

$sql = "insert namesdb values(".null.", 'firstname', 'lastname')"; $result = $db->query($sql); 

i syntax error...

any idea on heck i'm doing wrong here??

thank help!

it should be:

$sql = "insert namesdb values(null, 'firstname', 'lastname')"; $result = $db->query($sql); 

'null' string of "null".

though option (the 1 go with) list columns explicitly:

insert namesdb (firstname, lastname) values ('firstname', 'lastname') 

i prefer listing columns because more future proof, , it's easier see what's going on. imagine if columns rearranged, added, or removed in future. fixing queries going massive pain if have remove 6th unnamed parameter everywhere (for example).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -