Jump to content

[SOLVED] Total MySQL newbie in need of help!


Tylor_Famous

Recommended Posts

I am kind of new to MySql and am trying to make my first "real" project. I want to make a simple forum and I believe (I am trying to follow a book) that I want to send two query’s (one to forum_post and the other to forum_topics). Anyway it might be easier to just look... Also if it helps I use MySQLAdmin from godaddy...

 

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


//connect to server
$host = 'myserver'; 
$user = 'myuser';
$pass = 'mypass';
$database = 'mydb';
mysql_connect($host,$user,$pass) or die(mysql_error());

//Set of variables

$topic_create_time = date('D M j');
$topic_title = $_POST['topic_title']; 
$topic_owner = $_POST['topic_owner']; 

$post_create_time = date('D M j'); 
$post_title = $_POST['post_title']; 
$post_owner = $_POST['post_owner']; 

//Send first Query
mysql_select_db($database) or die(mysql_error());
$add_all_topic = "INSERT INTO forum_topics values('$topic_create_time' , '$topic_title', '$topic_owner')";
mysql_query($add_all_topic) or die(mysql_error());


//Send off second query
mysql_select_db($database) or die(mysql_error());
$add_all_post = "INSERT INTO forum_post values('$post_create_time' , '$post_title', '$post_owner')";
mysql_query($add_all_post) or die(mysql_error());


//Close conection to MySQL
mysql_close($mysql);

//Create a nice message for user
$display_block = "<p> The <strong> ".$_POST["topic_title"]."</strong> topic has been created.</p>";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Topic Added</title>
</head>

<body>
<h1>New Topic Added</h1>
<?php echo $display_block; ?>
</body>
</html>

 

When I do this, I get the message "Column count doesn't match value count at row 1".

Like I said I am a bit new so if I just hopelessly messed up the code please let me know!

But still, any help at all would be GREAT! Thanks so much...

Link to comment
Share on other sites

Let's examine the error

 

"Column count doesn't match value count at row 1".

 

This is referring to the number of columns you are trying to send compared to how many columns you have in the table.

 

So if you have 4 columns in your table, and you try to send just 3, you will get that error.

 

You can either specify which columns you want to insert into or you can specify values for each column

 

$add_all_topic = "INSERT INTO forum_topics (column1, column2, column3) values('$topic_create_time' , '$topic_title', '$topic_owner')";

 

Link to comment
Share on other sites

Yes! I was forgetting about the ID field. I added that one in and it seemed to work half way. I got his.

 

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in blahblah/html/testing/1.13.07/mysqlforum/do_addtopic.php on line 39

 

Line 38-39 is

 

//Close connection to MySQL

mysql_close($mysql);

 

what is wrong with line 39? lol thanks for the help by the way!

 

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.