twilitegxa Posted August 24, 2008 Share Posted August 24, 2008 I am working with a book tutorial and I can't figure out what i'm doing wrong. Can anyone take a look at my code and see if they see any recognizable problems? The error message I'm getting is: Column count doesn't match value count at row 1 Here is my code: <?php //check for required fields from the form if ((!$_POST[topic_owner]) || (!$_POST[topic_title]) || (!$_POST[post_text])) { header("Location: addtopic.html"); exit; } //connect to server and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$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> And the form page is: <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"> <input type="reset" name="reset" value="Reset"></p> </form> </body> </html> Does anyone see the reason for the error message? Also, here is the MySQL statement I 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 into not null primary key auto-increment, topic_id int not null, post_text text, post_owner varchar (150) ); Link to comment https://forums.phpfreaks.com/topic/121063-solved-php-help-with-discussion-forum-nevermind-fixed-it/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.