[HELP] PHP Auto Increment not working?

Status
Not open for further replies.

Mitchul

Sledmoresux
Feb 18, 2012
371
46
I'm fairly new to PHP, and made this script last year sometime..
PHP:
 <?php
 
if($_POST['submit']){
    $date = date("Y-m-d H:i:s");
    $change = $_POST['theUpdate'];
    mysql_query("INSERT INTO `changelog` VALUES ('', '".$change."', '".$date."')") or die(mysql_error());
    $msg = "The change has successfully been added to the changelog.";
 
}
?>

What it does is simply inserts text that you can have as a changelog..
The point is, on XAMPP the code works flawlessly, but when I moved to IIS, the code pretty much shat itself..

When I use the html code to post the change, I get the following error..

Incorrect integer value: '' for column 'id' at row 1

Any help?
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
If you set the ID field to Auto Increment in the database, it should automatically do it when a new record is added -- you don't even need the "''" in your code like you have.

You could just do:
PHP:
mysql_query("INSERT INTO `changelog` VALUES ('".$change."', '".$date."')") or die(mysql_error());
 

Mitchul

Sledmoresux
Feb 18, 2012
371
46
If you set the ID field to Auto Increment in the database, it should automatically do it when a new record is added -- you don't even need the "''" in your code like you have.

You could just do:
PHP:
mysql_query("INSERT INTO `changelog` VALUES ('".$change."', '".$date."')") or die(mysql_error());
I used the code above, but now I get this;
Column count doesn't match value count at row 1
 

Twix

Member
Mar 31, 2012
81
8
PHP:
mysql_query("INSERT INTO `changelog` (`change`, `date`) VALUES ('".$change."', '".$date."')") or die(mysql_error());

Change the change & date to the correct names and it should work.
 

Mitchul

Sledmoresux
Feb 18, 2012
371
46
PHP:
 <?php
 
if($_POST['submit']){
    $date = date("Y-m-d H:i:s");
    $change = $_POST['theUpdate'];
    mysql_query("INSERT INTO `changelog` (`date`, `change`) VALUES ('".$change."', '".$date."')") or die(mysql_error());
    $msg = "The change has successfully been added to the changelog.";
 
}
?>

Still the same..
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
PHP:
 <?php
 
if($_POST['submit']){
    $date = date("Y-m-d H:i:s");
    $change = $_POST['theUpdate'];
    mysql_query("INSERT INTO `changelog` (`date`, `change`) VALUES ('".$change."', '".$date."')") or die(mysql_error());
    $msg = "The change has successfully been added to the changelog.";
 
}
?>

Still the same..
Why are you attempting to put the change in the date column and the date in the change column?
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
Well the code is correct and should definitely work. Double check your database and check the table name is correct and the field names are correct too.
 
Status
Not open for further replies.

Users who are viewing this thread

Top