simcoweb Posted March 1, 2007 Share Posted March 1, 2007 Ok, simple stuff. I'm writing a quickie script to insert a user (username & encrypted password) into a mysql table for the purpose of adding an administrator/user/login. I have this: $username = "bozotheclown"; $password = md5("bozosbigtop"); with query written in standard stuff: $sql = "INSERT INTO admin_table (username, password) VALUES '$username', '$password'"; But I get a mysql error: 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 ''bozotheclown', '7627a74990b4087d37e591b6f8063599' at line 1 I've not used the md5 for anything yet so not familiar with how i'd set this up. Quote Link to comment Share on other sites More sharing options...
magnetica Posted March 1, 2007 Share Posted March 1, 2007 What is the field types for password? And whats the maximum length for it? Quote Link to comment Share on other sites More sharing options...
bwochinski Posted March 1, 2007 Share Posted March 1, 2007 Put your values in ( ) :: $sql = "INSERT INTO admin_table (username, password) VALUES ('$username', '$password')"; Quote Link to comment Share on other sites More sharing options...
simcoweb Posted March 1, 2007 Author Share Posted March 1, 2007 I got it to insert and to encrypt it by changing to this: <?php $username = "bozotheclown"; $password = "bozosbigtop"; $enc_password = md5($password); // run query to insert include 'dbconfig.php'; // Connect to database $con = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname, $con) or die(mysql_error()); $sql = "INSERT INTO eastside_admin (username, password) VALUES ('$username', '$enc_password')"; $results = mysql_query($sql) or die(mysql_error()); ?> But, when I try to validate that it worked I get an error using this code: <?php $num_rows = mysql_affected_rows($results); if ($num_rows == 1) { echo "Administrator successfully added"; } else { echo "Could not insert administrator for some reason."; } ?> What's strange is that it IS inserting the user info but then fails on the validation and shows the "Could not insert..." message. When I view the database I see the entry, however. Quote Link to comment Share on other sites More sharing options...
bwochinski Posted March 1, 2007 Share Posted March 1, 2007 you don't pass the result to mysql_affected_rows(), you pass a link identifier. $num_rows = mysql_affected_rows($con); Quote Link to comment Share on other sites More sharing options...
simcoweb Posted March 1, 2007 Author Share Posted March 1, 2007 Ok, didn't know that. Thanks! No more errors 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.