 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
06-12-2008, 10:07 PM
|
#1 (permalink)
|
|
The Visitor
Join Date: Jun 2008
Posts: 3
Thanks: 2
|
MySQL INSERT INTO
Hi all,
First of im new anf it took me ages to fine the dam register page!
Ok my problem, I am trying to do a registration page.
All is going well untill it goes to put the data into the Database.
Here my code:
Code:
mysql_query("INSERT INTO `users` (username, password, email, activecode, activated, tut, status)
VALUES ($reg_username, $randompassword, $email, $code, 0, 0, Alive)") or die ('Error Registering');
It isnt working, it dies.
The fields I am inserting into arent the only fields in the Table.
Will this stop it? Just inserting into the defined fields and leaving the rest blank would be great letting them default.
If not I will do it the hard way.
Thanks for any posts, help and advice.
Dean.
|
|
|
|
06-12-2008, 10:28 PM
|
#2 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Have you checked mysql_error() to see what it says?
PHP Code:
if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error());
|
|
|
|
|
The Following 2 Users Say Thank You to delayedinsanity For This Useful Post:
|
|
06-13-2008, 07:28 AM
|
#3 (permalink)
|
|
The Visitor
Join Date: Jun 2008
Posts: 3
Thanks: 2
|
Thanks for the reply DI.
I put that line in and got this error:
Quote:
|
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, 5jagr8ap, 0, 0, Alive)' at line 2
|
I take it thats the email address thats messing up?
Will that be because I am only putting data into a few fields of the Table, not the whole of the table?
I still dont understand that, I will have another look in 10 mintues.
Thanks,
Dean.
|
|
|
|
06-13-2008, 02:55 PM
|
#4 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
It could be as simple as putting quotes around your values. Try;
PHP Code:
$q = "INSERT INTO `users` (username, password, email, activecode, activated, tut, status) ". "VALUES ('$reg_username', '$randompassword', '$email', '$code', 0, 0, 'Alive')";
mysql_query($q);
-m
|
|
|
|
06-13-2008, 05:03 PM
|
#5 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
You get that error because you're sending strings without quotes to the database. That works only if the destination field is of type number (any - double, int, what ever) and the value you're trying to insert/change is a number, aswell.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
06-13-2008, 05:16 PM
|
#6 (permalink)
|
|
The Visitor
Join Date: Jun 2008
Posts: 3
Thanks: 2
|
Ok, now I get:
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
Im confused.
The code is:
Code:
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 from the table.
The code is inserting into the only columns in the table in order.
Thanks for the responses,
Dean.
|
|
|
|
06-13-2008, 05:34 PM
|
#7 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Try removing the quotes from your column names, but keep them around your values, and see if that does the trick.
-m
|
|
|
|
06-19-2008, 10:47 PM
|
#8 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
Or try use the ` quotes insted of single quote signs
__________________
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|