NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page MySql insert problem

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-08-2006, 08:20 AM THREAD STARTER               #1 (permalink)
New Member
Join Date: Jan 2006
Location: the Netherlands
Posts: 7
Chuppa is an unknown quantity at this point
 



Question MySql insert problem


Hi all,

I've made a newsletter subscription system for a website. It takes information from a small form and submits it into two tables in the database, one User table and one Userinfo table. It has always worked so far, but some time ago we moved to another hosting. Now, the script doesn't work properly anymore. I can't be completely sure it's because of the change of hosting, but it soiunds logical.

Anyway; here's the error message and code. I've thoroughly reviewed it and I can't see any mistakes or faulty code. Apparently; something's wrong with the first insertion. I've checked the second insertion and that one does work properly. Since both are the same, I have no idea why the first won't work.

Does anyone have a clue what the problem is? I'd be eternally grateful .

Error message:
Code:
Something went wrong. Please try again. 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 'User(Username,Password,Permission) VALUES( 'username','080f651e3f
PHP script:

PHP Code:
// if the required fields have been filled out
if($_POST['form_user'] AND $_POST['form_pass'] AND $_POST['form_email']) {

    
// if the passwords are equal
    
if($_POST['form_pass'] == $_POST['form_pass2']) {

        
// if user not already registered
        
$q "SELECT * FROM User WHERE Username = '" $_POST['form_user'] . "'";
        
$result mysql_query($q);
        if(
mysql_num_rows($result) == 0) {
????: NamePros.com http://www.namepros.com/programming/225527-mysql-insert-problem.html
            
// insert the user information
            
$pass md5($_POST['form_pass']);
            
$q "INSERT INTO User(Username,Password,Permission) VALUES(
            '" 
$_POST['form_user'] . "','" $pass "','1'
            )"
;

            if(
mysql_query($q)) {

                
$id mysql_insert_id();
????: NamePros.com http://www.namepros.com/showthread.php?t=225527

                
// insert the personal information
                
$q "INSERT INTO UserInfo(Name,UserSeq,Email,Country,Format,Newsletter,Promotion,UserType) VALUES(
                '" 
$_POST['form_name'] . "','" $id "','" $_POST['form_email'] . "','" $_POST['form_country'] . "',
                '" 
$_POST['form_format'] . "','" $_POST['form_newsletter'] . "','" $_POST['form_promotion'] . "','4'
                )"
;
                if(
mysql_query($q)) {
                    
// registration went ok. Email is sent. 
Chuppa is offline  
Old 08-08-2006, 08:58 AM   #2 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



Not knowing your database schema doesn't help, but I'm wondering: is your 'Permission' column a number type or a string type? I'm assuming it's a number type, in which case you shouldn't have those single quotes around the permission value you are trying to set. That could be a problem...

For example, change:
PHP Code:
$q "INSERT INTO User(Username,Password,Permission) VALUES(
            '" 
$_POST['form_user'] . "','" $pass "','1'
            )"

to:
PHP Code:
$q "INSERT INTO User(Username,Password,Permission) VALUES(
????: NamePros.com http://www.namepros.com/showthread.php?t=225527
            '" 
$_POST['form_user'] . "','" $pass "',1
            )"

If this fixes this particular issue, then I daresay you'll start getting errors elsewhere, whever you've added single quotes around number type values (eg. maybe your userType value?).
TwistMyArm is offline  
Old 08-08-2006, 09:59 AM   #3 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,556
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
It could be a problem with magic_quotes not enabled on the new server
http://www.php.net/magic_quotes

Are you trying to insert a string which contains a ' by chance ?
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline  
Old 08-08-2006, 10:28 AM   #4 (permalink)
Eating Pie
 
iNod's Avatar
Join Date: Nov 2004
Location: Canada
Posts: 2,272
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
 


Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Try printing your querys and see what you get?

I suspect there is a problem with your query somewhere.. Either a mis-named column or a missing one. I suggest you check your names and make sure everything is spelt right. Generally where it stops off is where the problem is.

- Steve
__________________
I feel old.
iNod is offline  
Old 08-08-2006, 05:45 PM THREAD STARTER               #5 (permalink)
New Member
Join Date: Jan 2006
Location: the Netherlands
Posts: 7
Chuppa is an unknown quantity at this point
 



Thanks for replies guys.

I printed the query, it looked as follows:
PHP Code:
INSERT INTO User(Username,Password,PermissionVALUES'tyu','af27bab84283536c346b97ced4bc5c58','1' 
The password, where the error messae stops, is simply an md5 code so it doesn't contain any quotes etc.

Twisty: the field is indeed an integer, so I shouldn't use the quotes. Still though, in other partsd of the script, I used quotes for integers as well and they don't give out an error. I'll check and see if it works, though.
????: NamePros.com http://www.namepros.com/showthread.php?t=225527

EDIT: Nope, that wasn't the problem. Using the code you suggested, it still gives out the same error message.

Any ideas?
Chuppa is offline  
Old 08-08-2006, 06:38 PM   #6 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Well first off, MySQL considers columns with names Username and username to be different (notice the capitals, so I would siggest first removing the capitals from the column names, so your code would become this:
????: NamePros.com http://www.namepros.com/showthread.php?t=225527
Code:
 $q = "INSERT INTO User(username,password,permission) VALUES(
            '" . $_POST['form_user'] . "','" . $pass . "','1'
            )";
If that’s not the problem, try this, even though it may seem useless:

Code:
$pass = md5($_POST['form_pass']);
$fUser=$_POST['form_user']
$q = "INSERT INTO User(Username,Password,Permission) VALUES('" .$fUser . "','" . $pass . "','1')";
All the best, Rhett.
BillyConnite is offline  
Old 08-08-2006, 08:25 PM   #7 (permalink)
NamePros Regular
 
Noobie's Avatar
Join Date: Feb 2006
Location: Montreal, Quebec, Canada
Posts: 324
Noobie is on a distinguished road
 



if none of the above works, maybe password or permission is a reserved name
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator
Noobie is offline  
Old 08-18-2006, 05:40 PM THREAD STARTER               #8 (permalink)
New Member
Join Date: Jan 2006
Location: the Netherlands
Posts: 7
Chuppa is an unknown quantity at this point
 



Thanks for the help guys, a friend of mine solved the problem. It turned out the User tablename is reserved on this server while it probably wasn't on the old.

Thanks for the support anyway!
Chuppa is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 03:40 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger