help with discussion forum user input form and scripts
Posted by: black85 (---.ipt.aol.com)
Date: July 06, 2006 10:27PM

Hi people,
I'm trying to create a discussion forum which involves developing database tables, user input html forms and display of the results, but unfortunately i have been getting this error message - 'column count doesn't match value count at row 1'.

The following below are the Mysql database tables, user input htm form and php scripts used:

create table forum_topics
(
topic_id int not null primary key auto_increment,
topic_title varchar(150),
topic_create_time datetime,
topic_owner varchar(150)
);


create table forum_posts
(
post_id int not null primary key auto_increment,
topic_id int not null,
post_text text,
post_create_time datetime,
post_owner varchar(150)
);

addtopic.html
---------------
<html>
<head>
<title>Add a Topic</title>
</head>
<body>
<h1>Add a Topic</h1>
<form method=post action="do_addtopic.php">
<p><strong>Your E-Mail Address/strong><br>
<input type="text" name="topic_owner" size=40 maxlength=150>
<p><strong>Topic Title/strong><br>
<input type="text" name="topic_title" size=40 maxlength=150>
<P><strong>Post Text/strong><br>
<textarea name="post_text" rows=8 cols=40 wrap=virtual></textarea>
<P><input type="submit" name="submit" value="Add Topic"></p>
</form>
</body>
</html>

do_addtopic.php
-----------------
<?php
//check for required fields from the form
if ((!$_POST[topic_owner]) || (!$_POST[topic_title])|| (!$_POST[post_text])) {
header("Location: addtopic.html"winking smiley;
exit;
}

//connect to server and select database
$conn = mysql_connect("localhost", "joeuser", "somepass"winking smiley or die(mysql_error());
mysql_select_db("testDB",$conn) or die(mysql_error());

//create and issue the first query
$add_topic = "insert into forum_topics values ('', '$_POST[topic_title]', now(), '$_POST[topic_owner]')";
mysql_query($add_topic,$conn) or die(mysql_error());

//get the id of the last query
$topic_id = mysql_insert_id();

//create and issue the second query
$add_post = "insert into forum_posts values ('', '$topic_id','$_POST[post_text]', now(), '$_POST[topic_owner]')";
mysql_query($add_post,$conn) or die(mysql_error());

//create nice message for user
$msg = "<P>The <strong>$topic_title</strong> topic has been created.</p>";
?>
<html>
<head>
<title>New Topic Added</title>
</head>
<body>
<h1>New Topic Added</h1>
<?php print $msg; ?>
</body>
</html>

error message displayed -
-------------------------
'column count doesn't match value count at row 1'.


Please tell me where i'm going wrong a.s.a.p

black85

Options: ReplyQuote
Re: help with discussion forum user input form and scripts
Posted by: CyberSpatium (67.170.181.---)
Date: July 07, 2006 01:58AM

change:
$add_topic = "insert into forum_topics values ('', '$_POST[topic_title]', now(), '$_POST[topic_owner]')";

to
$add_topic = "INSERT INTO forum_topics (topic_id, topic_title, topic_create_time, topic_owner) VALUES ('', '$_POST[topic_title]', now(), '$_POST[topic_owner]')";

change:
$add_post = "insert into forum_posts values ('', '$topic_id','$_POST[post_text]', now(), '$_POST[topic_owner]')";

to
$add_post = "INSERT INTO forum_posts (post_id, topic_id, post_text, post_create_time, post_owner varchar) VALUES ('', '$topic_id','$_POST[post_text]', now(), '$_POST[topic_owner]')";

Options: ReplyQuote


Sorry, only registered users may post in this forum.