Jump to content

Getting mysql error when trying to insert md5 password


simcoweb

Recommended Posts

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
Share on other sites

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
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.