PHP/SQL Error Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ehause
Forum Newbie
Posts: 9
Joined: Sat Apr 17, 2004 8:12 am

PHP/SQL Error Code

Post by ehause »

Almost there, BUT....

I have a register.php page connecting to my DB to INSERT form fields into the database. I'm connecting to the DB, but I am getting a PHP error when I submit:

"You could not be registered due to a system error. We apologize for any inconvenience.

Column count doesn't match value count at row 1"

I have checked that all my varibles match the database variables, but I'm not sure where to go from there.

I have no idea what this means and can't find reference to it anywhere. Any ideas, all you pros out there? Thanks in advance, you guys are great!

Eric
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

this is on an insert statement it basically means the number of values you are inserting doesnt match the number of fields you have declared
for eg

Code: Select all

// wrong
$insert = "INSERT INTO counter (IP, time, page) VALUES ('$ip_counter', NULL)";
// right
$insert = "INSERT INTO counter (IP, time, page) VALUES ('$ip_counter', NULL, '$page_counter')";
ehause
Forum Newbie
Posts: 9
Joined: Sat Apr 17, 2004 8:12 am

Post by ehause »

Malcolm, thanks so much...one last question:

The INSERT query posts to the DB, and all the values are getting posted to the correct fields--except the password is getting inserted as a DATETIME stamp in the PASSWORD field.

Nothing is getting inserted into the CREATED field, which is suppoed to be the DATETIME variable for when the record was created.

Here's the code I have:

// Make the query.
$query = "INSERT INTO members (username, first_name, last_name, email_address, password, created) VALUES ('$u', '$fn', '$ln', '$e', PASSWORD('$p'), NOW() )";
$result = @mysql_query ($query); // Run the query.
if ($result) { // If it ran OK.

What am i doing wrong? Is it in my VALUES order?
ehause
Forum Newbie
Posts: 9
Joined: Sat Apr 17, 2004 8:12 am

Post by ehause »

Malcolm:

These are the results from my DB after the record is inserted, showing the row names and the end results:

user_id /username /password /created /last_name /first_name /email_address

5/testagain/2004-04-20 10:08:26/0000-00-00 00:00:00/test/again
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

You are missing the value of password:

Code: Select all

// Make the query. 
$query = "INSERT INTO members (username, first_name, last_name, email_address, password, created) VALUES ('$u', '$fn', '$ln', '$e', PASSWORD('$p'), NOW() )";	
$result = @mysql_query ($query); // Run the query. 
if ($result) { // If it ran OK.
Your variables are getting messed up somehow... can you post those?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

What is this:

PASSWORD('$p')

a function?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

i think he has mininterpreted the password field

remove (password)

i think he is referring to a mysql field 'type'
ehause
Forum Newbie
Posts: 9
Joined: Sat Apr 17, 2004 8:12 am

Post by ehause »

Yup, that's it, thanks guys!
Post Reply