Tylor_Famous Posted January 23, 2008 Share Posted January 23, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/87317-solved-total-mysql-newbie-in-need-of-help/ Share on other sites More sharing options...
revraz Posted January 23, 2008 Share Posted January 23, 2008 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')"; Quote Link to comment https://forums.phpfreaks.com/topic/87317-solved-total-mysql-newbie-in-need-of-help/#findComment-446601 Share on other sites More sharing options...
Tylor_Famous Posted January 23, 2008 Author Share Posted January 23, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/87317-solved-total-mysql-newbie-in-need-of-help/#findComment-446608 Share on other sites More sharing options...
Tylor_Famous Posted January 23, 2008 Author Share Posted January 23, 2008 Oh yeah, it did input the information into the database though, even with the error. Quote Link to comment https://forums.phpfreaks.com/topic/87317-solved-total-mysql-newbie-in-need-of-help/#findComment-446609 Share on other sites More sharing options...
revraz Posted January 23, 2008 Share Posted January 23, 2008 You are not setting $mysql at the start to your connection. You can remove the line though, the connection will close when the page completes. Quote Link to comment https://forums.phpfreaks.com/topic/87317-solved-total-mysql-newbie-in-need-of-help/#findComment-446611 Share on other sites More sharing options...
Tylor_Famous Posted January 23, 2008 Author Share Posted January 23, 2008 Ok GREAT thanks sooo much for all your help! You will most likely be seeing me back here at least a dozen more times while I am making this forum! Thanks a million! Quote Link to comment https://forums.phpfreaks.com/topic/87317-solved-total-mysql-newbie-in-need-of-help/#findComment-446613 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.