Computer Science Canada query not working |
Author: | unknowngiver [ Tue May 30, 2006 10:22 am ] | ||||
Post subject: | query not working | ||||
Hey whats wrong with this code??
it gives me the error:
|
Author: | md [ Tue May 30, 2006 10:39 am ] |
Post subject: | |
echo the query instead of executing it and post it... without seeing what your doing it's hard to diagnose. |
Author: | md [ Tue May 30, 2006 10:45 am ] |
Post subject: | |
/me grubles about a lack of edit features... And also try running the query in say the mysql query browser and see what error it gives you. |
Author: | wtd [ Tue May 30, 2006 11:09 am ] | ||||
Post subject: | |||||
If you want the DB to automatically handle the "id" column, then simply do this:
Another problem: see how you have variables inside single-quoted strings? Well, in PHP, single-quoted strings don't do string interpolation. |
Author: | Amailer [ Tue May 30, 2006 11:12 am ] |
Post subject: | |
Obviously that means that the id field in your database is set to auto_increasement |
Author: | rdrake [ Tue May 30, 2006 5:04 pm ] | ||
Post subject: | |||
Strangely I found something like the following works better.
|
Author: | Blade [ Tue May 30, 2006 9:17 pm ] | ||||
Post subject: | |||||
yeah, for that you need to have the right info in the same order as the table so if you have id, username, password in that order in your table, you need to input the id, username, password in that order in your script but the way he did it, the information doesnt have to be in the exactly same order as the table, you just need each value to corrospond the way you declared it i dont remember for sure, so somebody correct me if i'm wrong, but when you declare which cells you're going to input data to, i dont think you need to use every cell in the table. so if you have id, username, email, password, name, phone number but you only want to add an id, username, email and password then you can use
whereas you'd have to say
personally, i think they both work alright ![]() |
Author: | wtd [ Tue May 30, 2006 9:37 pm ] |
Post subject: | |
Blade wrote: i dont remember for sure, so somebody correct me if i'm wrong, but when you declare which cells you're going to input data to, i dont think you need to use every cell in the table.
Indeed, and if you have an auto-incrementing id field, you should let the database handle it. |
Author: | octopi [ Tue May 30, 2006 9:44 pm ] | ||||||
Post subject: | |||||||
You can put the variable names like the OP did.
Hes using double qoutes not single qoutes. (the single qoutes are part of the sql string) or if you'd rather you can do
using {} ensures that the variable's name is recognised correctly say $width=5; and you wanted to print "5px" you could do "{$width}px", whereas if you wrote "$widthpx", it would try to load a different variable when I do inserts, I make them like my update statements like so:
|
Author: | wtd [ Tue May 30, 2006 9:47 pm ] | ||
Post subject: | |||
octopi wrote: You can put the variable names like the OP did.
Hes using double qoutes not single qoutes. (the single qoutes are part of the sql string) I knew that! Thanks for pointing out my mistake. ![]() |
Author: | Blade [ Wed May 31, 2006 8:40 am ] |
Post subject: | |
concatenating like i did works as well ![]() |
Author: | JackTruong [ Fri Jun 02, 2006 8:59 pm ] | ||
Post subject: | |||
Maybe it could be:
Take off the @ when using mysql_select_db and see if the error message changes. |