Jump to content

**FIXED ** Should be something simple with Account Registration Form...


thepip3r

Recommended Posts

This is my snytax for my SQL Insert:
[code=php:0] echo "INSERT INTO users(username,password,email,sex,city,state,country,created) VALUES('$un','".md5($pw1)."','$em1','$sex','$city','$state','$country','".strtotime("now")."')";
$query = mysql_query("INSERT INTO users(username,password,email,sex,city,state,country,created) VALUES('$un','$pw1','$em1','$sex','$city','$state','$country','".strtotime("now")."'") or die(error_handler("Error creating account information.",1,1));
db_close();
echo "Your account was successfully created.  Please log in to play! <br />";[/code]


When I echo the SQL, it's something like:
[code]INSERT INTO users(username,password,email,sex,city,state,country,created) VALUES('test','912ec803b2ce49e4a541068d495ab570','test@test.com','m','asdfk','asdfk','asdf','1162412485')[/code]


When my script processes the code, I get this error:
[quote]MySQL Error [1064]: 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 '' at line 1[/quote]

The funny thing is, I'm echoing out my SQL so I can see if there are any vars not being set, aren't getting \ commented, etc, etc and when I copy and paste the same SQL straight into the database through phpMyAdmin, it inserts the record correctly.  Can anyone see a problem with my syntax?? I'm at a loss...
Link to comment
Share on other sites

Well, the echo'd text is not showing up. But, I do see one problem:

You are creating the sql statement 2 times: one for echoing and one for running. That's not a good way to do that for the exact problem you are having now. if there is just one character different then you may have problems. You first create the sql statement as a variable, then use that variable for echoing and/or running. Then youcan be sure you are using the exact same data:

$sql = "INSERT INTO table (col1, col2, col3) VALUES ('one', 'two', 'three')";
echo $sql;
$query = mysql_query($sql);

I also noticed you are not converting the password into an MD5 hash in the actual query, but you are in the echo'd statement.
Link to comment
Share on other sites

Thank you for the oversite.  I did just copy the SQL statement from inside the mysql_query function and echo'd it just so I could make sure the vars were outputting correctly and then when I modded the password, i forgot to do it to the source. I'm familiar with making it a var but don't use it as it's an extra line of extraneous code (IMO).  The fact that I have it being echo'd means nothing; it's a string and is not interpreted as SQL unless you pass it through something like a function that's looking for SQL, it's nothing more than a bunch of characters and words strung together. 

I updated the source to input the $pw1 var as md5() also.  Still not working with the same error tho....
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.