Jump to content

INSTERT INTO - Not all feilds?


bravo81

Recommended Posts

Hi everyone, I am trying to INSTERT INTO my MySQL DB Table when someone registers.

 

But I do not want to create Values for every field, is that possible?

 

Its not working so far, I am defining the fields I wish to fill in with the Data supplied in the submit form.

 

mysql_query("INSERT INTO `users` (username, password, email, activecode, activated, tut, status)
VALUES ($reg_username, $randompassword, $email, $code, 0, 0, Alive)");
if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error()); 

 

 

The website is:

www.southernheavenflorida.com/quarantime.com

 

Thanks for any help/comments.

 

Dean.

Link to comment
Share on other sites

Thanks Fenway, I will try that.

 

I have not got Defaults in all off the Fields, but I am not listing hte Column name so it should just be ok yeh?

Im getting this error:

 

Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@hotmail.co.uk, ykyc4h67, 0, 0, Alive)' at line 2

 

The Email field has about 10 other fields between it and "Password".

Is that why the error comes up?

 

Thanks,

 

Dean.

Link to comment
Share on other sites

You didn't read my comment about the "alive" value before... quote it!  In fact, quote all of your values!

 

mysql_query("INSERT INTO `users` (username, password, email, activecode, activated, tut, status)
VALUES ('$reg_username', '$randompassword', '$email', '$code', 0, 0, 'Alive')");
if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error()); 

 

Link to comment
Share on other sites

I have done that,

 

Now my code is:

 

mysql_query("INSERT INTO `users` ('username', 'password', 'activated', 'online', 'email', 'status', 'tut', 'activecode')
VALUES ('$reg_username', '$randompassword', '0', '0', '$email', 'Alive', '0', '$code')");
if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error()); 

 

I have removed all other columns that I am not using.

Also, the code is inserting into the columns in order.

 

The error I get now is:

 

Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''username', 'password', 'activated', 'online', 'email', 'status', 'tut', 'active' at line 1

 

Any ideas?

 

Thanks,

 

Dean.

Link to comment
Share on other sites

Only place quotes around values, not field/table names.

 

mysql_query("INSERT INTO `users` (username, `password`, activated, online, email, status, tut, activecode)
VALUES ('$reg_username', '$randompassword', '0', '0', '$email', 'Alive', '0', '$code')");
if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error()); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.