Coding, Design & GraphicsIf you are programming a script, designing a web page, building your own graphics or anything related and need to discuss it, get help and tips or general advice, then you should post your thoughts to this section.
I'm having trouble inserting info from my php script to my database. Can anyone tell me why? Here's what my script looks like:
// write to database
mysql_query ('INSERT into members (first_name, last_name, email) VALUES ("chas", "nacio", "cwyke-smith@nacio.com")', $connectID)
or die ("Unable to insert record into database");
Try one of these, they come with tutorials, which is better than me just simply posting the answer to you direct, after all learning to do it yourself is better for your coding skills in the long term:
Although to be honest, the insert command is one of the most simple commands, so if you've not got to the point of doing those codes as second nature, i'd really suggest getting hold of a few php/mysql books from the library or something and sitting and reading them and doing all the little exercises in them.
At a glance your statement looks fine, although im more than a little rusty with sql these days. I recall that the most common reason i got that problem, would be that there was a field in the table not being filled, or incorrect data type. Its also possible that your connection isnt right, as youve only shown a small part of the script - you need to get the connectID from the initial db connection you make.
Honestly without seeing more of the script, knowing your competence level with php (if youre new etc), and seeing your database table structure, its hard to diagnose any problem. Also knowing if you have direct/shell access would allow different approaches to checking things and being able to more closely examine the database - although you will probably have something like that php myadmin thingy if not.
Hope this is vaguely useful, and check out dets links above - with some previous experience those links and others helped me just dive headlong into it
I don't really do php/mysql but standard SQL doesn't allow " (double quote) for string literals you need to use ' (single quotes) and to use ' inside a string literal itself you need to double it up, eg. ' becomes '' (2 single quotes). Or if php is like C/C++ escape it, e.g. \'
I don't really do php/mysql but standard SQL doesn't allow " (double quote) for string literals you need to use ' (single quotes) and to use ' inside a string literal itself you need to double it up, eg. ' becomes '' (2 single quotes). Or if php is like C/C++ escape it, e.g. \'
Hmm interesting, i presumed it wasnt fussy, php's syntax at least seems quite tolerant. What do you mean by standard sql btw, surely not the evil M$ variant?
Id always just done mysql_query("sql statement('string')");