Jump to content


Photo

Column count doesn't match value count at row 1


  • Please log in to reply
9 replies to this topic

#1 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 16 July 2006 - 08:32 AM

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
:

<?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());

?>


#2 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 16 July 2006 - 08:58 AM

What line/query gives you the error?
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#3 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 16 July 2006 - 08:59 AM

No line...the title of this thread is the exact thing it says.

#4 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 16 July 2006 - 09:03 AM

"INSERT INTO `topics` (`id`, `fid` , ... )VALUES ('', '1', ...

Telling it to add ID with value '' may be causing the problem. Remove ID and its corrisponding value. Auto incriment fields are named that for a reson ;)
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#5 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 16 July 2006 - 10:32 AM

no, neither way works! very odd...

#6 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 16 July 2006 - 10:37 AM

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)
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#7 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 16 July 2006 - 10:43 AM

/* ***** 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!

#8 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 16 July 2006 - 10:53 AM

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!
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#9 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 16 July 2006 - 09:28 PM

What? They are the same, I am still having big trouble with this script and it's getting really annoying...

#10 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 16 July 2006 - 09:32 PM

omg, I never noticed, I was missing a comma after administrator. All works now, don't I feel stupid.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users