Jump to content

Column count doesn't match value count at row 1


localhost

Recommended Posts

I've read up, and apparently it has to do with one of the columns auto incrementing, although I checked mine and can't find the problem. Any ideas? heres the code
:

[code]
<?php

include('../inc/connect.php');

/* ***** CREATE TABLE `categories` ***** */
$ct = "CREATE TABLE `categories` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL,
  `description` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
)";
$ctr = mysql_query($ct) or die(mysql_error());

/* ***** CREATE TABLE `forums` ***** */
$ct2 = "CREATE TABLE `forums` (
  `id` int(11) NOT NULL auto_increment,
  `cat_name` varchar(70) default NULL,
  `title` varchar(255) NOT NULL,
  `description` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
)";
$ctr2 = mysql_query($ct2) or die(mysql_error());

/* ***** CREATE TABLE `posts` ***** */
$ct3 = "CREATE TABLE `posts` (
  `id` int(11) NOT NULL auto_increment,
  `tid` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `post` longtext NOT NULL,
  `poster` varchar(50) NOT NULL,
  `ip` varchar(40) NOT NULL,
  `date` varchar(20) NOT NULL,
  `le_user` varchar(50) default NULL,
  `le_time` varchar(50) default NULL,
  PRIMARY KEY  (`id`)
)";
$ctr3 = mysql_query($ct3) or die(mysql_error());

/* ***** CREATE TABLE `topics` ***** */
$ct4  = "CREATE TABLE `topics` (
  `id` int(11) NOT NULL auto_increment,
  `fid` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `post` longtext NOT NULL,
  `poster` varchar(50) NOT NULL,
  `date` varchar(20) NOT NULL,
  `replies` int(11) NOT NULL,
  `ip` varchar(25) NOT NULL,
  `views` int(11) NOT NULL,
  `le_user` varchar(50) default NULL,
  `le_time` varchar(50) default NULL,
  PRIMARY KEY  (`id`)
)";
$ctr4 = mysql_query($ct4) or die(mysql_error());

/* ***** CREATE TABLE `users` ***** */
$ct5 = "CREATE TABLE `users` (
  `id` int(11) NOT NULL auto_increment,
  `username` varchar(50) NOT NULL,
  `password` varchar(40) NOT NULL,
  `email` varchar(50) NOT NULL,
  `regip` varchar(40) NOT NULL,
  `regdate` varchar(20) NOT NULL,
  `user_level` int(11) NOT NULL,
  `postcount` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
)";
$ctr5 = mysql_query($ct5) or die(mysql_error());

$ip = $_SERVER['REMOTE_ADDR'];
$date = date('m-d-Y');

$password = sha1('yourforumsystem');

/* ***** INSERT DEFAULT ADMIN ***** */
$sql = "INSERT INTO users VALUES ('', 'Administrator' '$password', 'email', '$ip', '$date', '10', '0')";
$sqlr = mysql_query($sql) or die(mysql_error());

/* ***** INSERT DEFAULT CATEGORY ***** */
$sql2 = "INSERT INTO `categories` (`id`, `title` , `description` ) VALUES ('', 'YourForumSystem', '');";
$sqlr2 = mysql_query($sql2) or die(mysql_error());

/* ***** INSERT DEFAULT FORUM ***** */
$sql3 = "INSERT INTO `forums` (`id`, `cat_name` , `title` , `description` )VALUES ('', 'YourForumSystem', 'YourForumSystem', 'Thank you for installing YourForumSystem');";
$sqlr3 = mysql_query($sql3) or die(mysql_error());

/* ***** INSERT DEFAULT THREAD ***** */
$sql4 = "INSERT INTO `topics` (`id`, `fid` , `title` , `post` , `poster` , `date` , `replies` , `ip` , `views` , `le_user` , `le_time` )VALUES ('', '1', 'Welcome to YFS', 'Thank you for installing YourForumSystem. You may now delete this post, edit it, and continue maintaining your forum with one of the best forum systems around, YourForumSystem.', 'Administrator', '$date', '0', '$ip', '0', NULL , NULL);";
$sqlr4 = mysql_query($sql4) or die(mysql_error());

?>
[/code]
add better error checking to see where the problem really is?
eg: $sqlr3 = mysql_query($sql3) or die(mysql_error() . 'I died doing xxxx!');
(for debugging purposes only, of course)

and the problem may lay with:

/* ***** INSERT DEFAULT ADMIN ***** */
$sql = "INSERT INTO users VALUES ('', 'Administrator' '$password', 'email', '$ip', '$date', '10', '0')";
$sqlr = mysql_query($sql) or die(mysql_error());

as you dont explicitly define the colums the values go with. (should always, ALWAYS do that)
/* ***** INSERT DEFAULT ADMIN ***** */
$sql = "INSERT INTO users (`id`, `username`, `password`, `email`, `regip`, `regdate`, `user_level`, `postcount`) VALUES ('', 'Administrator' '$password', 'email', '$ip', '$date', '10', '0')";
$sqlr = mysql_query($sql) or die(mysql_error(). 'I died doing a porno!');

With that I got:
Column count doesn't match value count at row 1I died doing a porno!
Do you validate user input? should always do that.


oooh!
$sql4 = "INSERT INTO `topics` (`id`, `fid` , `title` , `post` , `poster` , `date` , `replies` , `ip` , `views` , `le_user` , `le_time` )VALUES ('', '1', 'Welcome to YFS', 'Thank you for installing YourForumSystem. You may now delete this post, edit it, and continue maintaining your forum with one of the best forum systems around, YourForumSystem.', 'Administrator', '$date', '0', '$ip', '0', NULL , NULL);";

Number of items in values is 1 less then the number defined!

I love it when i find stupid mistakes like that xD Removes the stress of looking for em!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.