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. Link to comment https://forums.phpfreaks.com/topic/40760-getting-mysql-error-when-trying-to-insert-md5-password/ 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? Link to comment https://forums.phpfreaks.com/topic/40760-getting-mysql-error-when-trying-to-insert-md5-password/#findComment-197315 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')"; Link to comment https://forums.phpfreaks.com/topic/40760-getting-mysql-error-when-trying-to-insert-md5-password/#findComment-197331 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. Link to comment https://forums.phpfreaks.com/topic/40760-getting-mysql-error-when-trying-to-insert-md5-password/#findComment-197381 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); Link to comment https://forums.phpfreaks.com/topic/40760-getting-mysql-error-when-trying-to-insert-md5-password/#findComment-197385 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 Link to comment https://forums.phpfreaks.com/topic/40760-getting-mysql-error-when-trying-to-insert-md5-password/#findComment-197393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.