View Full Version : PHP/MySQL Inserting Data

03-30-2007, 02:55 AM
Hey All,

I posted about this before but when I finally tried it I got some weird errors because I was using my own custom encryption function. So basically I have a table with un-encrypted passwords, and I want to turn them all into encrypted ones. So I use this sql:

UPDATE TABLE rp_users SET passwrd = enc(`passwrd`)

And I get this error.... and just so you know the "enc" function is a php function that is included in the page that just uses a series of complicated encryption strings on the password.

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 '(`passwrd`)' at line 1

And when I changed my SQL to this:

UPDATE rp_users SET passwrd = 'enc(`passwrd`)'

I don't get any errors, but instead of using the encryption function of the "password" of the table row it just inserts "enc(`passwrd`)" as the users new password. And I have also tried making the encryption part a variable and using the variable in the actual SQL String but when I do that it just encrypts "passwrd" instead of the actual password from the database.

Any help would be really great! Thanks so much! :)

03-30-2007, 03:00 AM
Nevermind... finally got it to work... for anyone who wants to know the code is below:

$result = mysql_query("SELECT passwrd FROM users");
$row = mysql_fetch_array($result);
$cpass = $row['passwrd'];
$encpass = enc($cpass);
$queryf = "UPDATE users SET passwrd = '$encpass'";
$result = mysql_query($queryf) or die(mysql_error());