TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-12-2008, 10:07 PM   #1 (permalink)
The Visitor
 
Join Date: Jun 2008
Posts: 3
Thanks: 2
Bravo81 is on a distinguished road
Terminal 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.
Bravo81 is offline  
Reply With Quote
Old 06-12-2008, 10:28 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Have you checked mysql_error() to see what it says?

PHP Code:
if (mysql_affected_rows() != 1) die ('Query failed: '.mysql_error()); 
delayedinsanity is offline  
Reply With Quote
The Following 2 Users Say Thank You to delayedinsanity For This Useful Post:
Bravo81 (06-13-2008)
Old 06-13-2008, 07:28 AM   #3 (permalink)
The Visitor
 
Join Date: Jun 2008
Posts: 3
Thanks: 2
Bravo81 is on a distinguished road
Help

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.
Bravo81 is offline  
Reply With Quote
Old 06-13-2008, 02:55 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 06-13-2008, 05:03 PM   #5 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
xenon is offline  
Reply With Quote
Old 06-13-2008, 05:16 PM   #6 (permalink)
The Visitor
 
Join Date: Jun 2008
Posts: 3
Thanks: 2
Bravo81 is on a distinguished road
Angry

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.
Bravo81 is offline  
Reply With Quote
Old 06-13-2008, 05:34 PM   #7 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Try removing the quotes from your column names, but keep them around your values, and see if that does the trick.
-m
delayedinsanity is offline  
Reply With Quote
Old 06-19-2008, 10:47 PM   #8 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Or try use the ` quotes insted of single quote signs
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:16 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design