phoenixshade
04-28-2007, 10:51 PM
I'm having a problem with a simple php statement to INSERT INTO an existing database where the first field is an AUTO INCREMENT NOT NULL field. How do I get my script to properly insert records? Right now, it fails.
Here's the create table statement:
CREATE TABLE members (
id int NOT NULL auto_increment,
username varchar(20) NOT NULL default '',
password char(32) binary NOT NULL default '',
email varchar(50) NOT NULL default '',
onlist tinyint(1) NOT NULL default 0,
cookie char(32) binary NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY (username)
And here's the addUser function:
function addUser($email,$username,$password,$notify) {
global $con;
$md5pass = md5($password);
$cookie = md5($username . $password);
mysql_select_db('lnusser_chesslive',$con);
$sql = "INSERT INTO members (username,password,email,onlist,cookie) ";
$sql .= "VALUES ($username,$md5pass,$email,$notify,$cookie)";
if (!mysql_query($sql)) {
die('Insert Row Failed!');
}
}
Execution dies with 'Insert Row Failed!' whenever the addUser function is called. I have already made sure there are no NULL values being passed to the function. The only thing I can imagine is causing this is that the auto-increment field is not being populated, which defeats the purpose of the 'auto' if you ask me.
Thanks for your help!
Here's the create table statement:
CREATE TABLE members (
id int NOT NULL auto_increment,
username varchar(20) NOT NULL default '',
password char(32) binary NOT NULL default '',
email varchar(50) NOT NULL default '',
onlist tinyint(1) NOT NULL default 0,
cookie char(32) binary NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY (username)
And here's the addUser function:
function addUser($email,$username,$password,$notify) {
global $con;
$md5pass = md5($password);
$cookie = md5($username . $password);
mysql_select_db('lnusser_chesslive',$con);
$sql = "INSERT INTO members (username,password,email,onlist,cookie) ";
$sql .= "VALUES ($username,$md5pass,$email,$notify,$cookie)";
if (!mysql_query($sql)) {
die('Insert Row Failed!');
}
}
Execution dies with 'Insert Row Failed!' whenever the addUser function is called. I have already made sure there are no NULL values being passed to the function. The only thing I can imagine is causing this is that the auto-increment field is not being populated, which defeats the purpose of the 'auto' if you ask me.
Thanks for your help!