I have the following code:
$username_sqlsa fe = addslashes($dat a['username']);
$email_sqlsafe = addslashes($dat a['email']);
$name_sqlsafe = addslashes($dat a['name']);
$location_sqlsa fe = addslashes($dat a['location']);
$password_md5 = md5($data['password']);
$remoteaddr = $_SERVER['REMOTE_ADDR'];
// do insert
$sql = "INSERT INTO users (username,passw ord,email,regis tered,
name,location,l ast_ip)
VALUES ('$username_sql safe','$passwor d_md5','$email_ sqlsafe',NOW(),
'$name_sqlsafe' ,'$location_sql safe','$remotea ddr')";
$query = mysql_query($sq l,$_db);
// end
The username field has a UNIQUE index.
Problem: when the username exists in the database $query comes out false.
But the PHP documentation says this shouldn't be the case, it should return
true and then mysql_affected_ rows() will return 0. And yes, this code works
when the username isn't in the database. I'm just confused, I doubt the
documentation is wrong, but I don't see what I could be doing if it works
fine when the username isn't in the db.
Thanks.
$username_sqlsa fe = addslashes($dat a['username']);
$email_sqlsafe = addslashes($dat a['email']);
$name_sqlsafe = addslashes($dat a['name']);
$location_sqlsa fe = addslashes($dat a['location']);
$password_md5 = md5($data['password']);
$remoteaddr = $_SERVER['REMOTE_ADDR'];
// do insert
$sql = "INSERT INTO users (username,passw ord,email,regis tered,
name,location,l ast_ip)
VALUES ('$username_sql safe','$passwor d_md5','$email_ sqlsafe',NOW(),
'$name_sqlsafe' ,'$location_sql safe','$remotea ddr')";
$query = mysql_query($sq l,$_db);
// end
The username field has a UNIQUE index.
Problem: when the username exists in the database $query comes out false.
But the PHP documentation says this shouldn't be the case, it should return
true and then mysql_affected_ rows() will return 0. And yes, this code works
when the username isn't in the database. I'm just confused, I doubt the
documentation is wrong, but I don't see what I could be doing if it works
fine when the username isn't in the db.
Thanks.
Comment