Jump to content

[SOLVED] PHP help with Discussion Forum - Nevermind, fixed it


twilitegxa

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.