thepip3r Posted November 1, 2006 Share Posted November 1, 2006 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... Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 1, 2006 Share Posted November 1, 2006 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. Quote Link to comment Share on other sites More sharing options...
thepip3r Posted November 1, 2006 Author Share Posted November 1, 2006 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.... Quote Link to comment Share on other sites More sharing options...
thepip3r Posted November 1, 2006 Author Share Posted November 1, 2006 Sorry for the post... i figured out my problem. In my SQL statement, I closed out my Values parenthesis but I didn't close out the one for mysql_query( Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 1, 2006 Share Posted November 1, 2006 To each his own. but putting the query into a variable takes so little time that it is not an issue. My point was that trying to echo a string of text as a debugging tool is not valid if you are not using the exact same text. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.