How do I get this code to work!

I cant seem to get this right. I have created if statements to diagnose where I keep on having the query error, and just like i thought, it was in the INSERT INTO code. Here is the code, can someone look at this for me and see if The code is in anyway wrong, (misspelling, punctuation and etc.?)

//error here.
   $query = "INSERT INTO register (id, company, att, racernum, phone, names, date) VALUES ('', '$company', '$att', '$racernum', '$phone', '$names', '$date')";

   mysql_query($query) or die('Error, query failed');


exit();

why are you putting a blank value into the id field?
if its an auto-increment primary key, then just leave that alone and it will automatically add it itself.

also, try two things:

  1. print out all your variables that you are inserting before the query…this way u can make sure that ur variables have no problems

  2. print out the query (ie. print $query;)
    this will show you wat you are trying to do so u can identify the problem in the query

try:

$query = "INSERT INTO register (company, att, racernum, phone, names, date) VALUES ('$company', '$att', '$racernum', '$phone', '$names', '$date')";
mysql_query($query) or die(mysql_error());

adding to what DHDesign said, if your id field is auto_increment, you should not be inserting any id value. it will automatically populate.

make sure your die’s are mysql_error() when testing so you get a better error message.

ok. Well, I seem to still be getting an error, but the detailed error did give me a different suggestion as to what the problem is, but I have no idea what the error means. I get this as the error.

“Duplicate entry ‘0’ for key 1”

Okay, I gotta be a retard, I just forgot to put the row as “auto increment”

hello.

well, thanks to everyone who helped, there were some tips that will be very useful.

no problem. for those that didn’t understand, the
"Duplicate entry ‘0’ for key 1" error message was because the field was set as a primary key, but skyler was unintentionally trying to insert a duplicate value. to fix the problem, just set as auto increment and make sure the starting auto increment number does not already exist in the table.