fantomel Posted August 25, 2008 Share Posted August 25, 2008 Column count doesn't match value count at row 1 << --- this is the error that gives it to me. <?php include("include/session.php"); if (isset($_GET['submit'])) { $name = trim(htmlspecialchars(strip_tags(addslashes($_POST['name'])))); $comment = trim(htmlspecialchars(strip_tags(addslashes($_POST['comment'])))); if ($name == "" || $comment == "") { echo "Some fields left blank. <a href='java script:history.go(-1)'>Try Again</a>"; } else { $id = $_POST['nid']; $date = date("d.m.Y"); $ip = $_SERVER["REMOTE_ADDR"]; $sql = mysql_query("INSERT INTO `news_comments` VALUES ('$id', '$name', '$comment', '$date', '$ip')") or die(mysql_error()); if ($sql) { echo "<script Language=\"JavaScript\"> var URL = \"view_comments.php?id=$id\" var speed = 0 function reload(){ location = URL } setTimeout(\"reload()\",speed); </script>"; } else { echo "failed."; } } } else { $id = $_GET['id']; ?> <form name="form1" method="post" action="?submit=true"> <table width="400" border="0"> <tr> <th scope="col">Name:<br> <input name="name" type="text" size="15"> </th> </tr> <tr> <td><div align="center"> <textarea name="comment" cols="40" rows="10" wrap="VIRTUAL"></textarea> <input type="hidden" value="<?php echo "$id"; ?>" name="nid"> </div></td> </tr> <tr> <td><div align="center"> <input name="submit" type="submit" id="submit" value="Add Comment"> </div></td> </tr> </table> </form> <? } ?> CREATE TABLE IF NOT EXISTS `news_comments` ( `id` int(5) NOT NULL auto_increment, `nid` int(5) NOT NULL, `user` varchar(15) NOT NULL, `comment` varchar(200) NOT NULL, `date` varchar(10) NOT NULL, `ip` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; can someone help please i don't know how to resolve the error.. i googled after it .. but couldn't find a solution thank you very much Quote Link to comment Share on other sites More sharing options...
ratcateme Posted August 25, 2008 Share Posted August 25, 2008 is that a mysql error? it doesn't seem to fit with that code as there is no column called 'count' Scott. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted August 25, 2008 Share Posted August 25, 2008 $sql = mysql_query("INSERT INTO `news_comments` VALUES ('$id', '$name', '$comment', '$date', '$ip')") or die(mysql_error()); Is it that? Quote Link to comment Share on other sites More sharing options...
Poddy Posted August 25, 2008 Share Posted August 25, 2008 You have incorrect syntex in your insert query it should be insert into table (colmuns) values (data) Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 25, 2008 Share Posted August 25, 2008 Try this: <?php $sql = mysql_query("INSERT INTO `news_comments` (`nid`, `user`, `comment`, `date`, `ip`) VALUES ('$id', '$name', '$comment', '$date', '$ip')") or die(mysql_error()); ?> Also, there are a few other things you may want to know: echo "Some fields left blank. <a href='java script:history.go(-1)'>Try Again</a>"; I don't think you can split the word "javascript" like that. if ($sql) { echo "<script Language=\"JavaScript\"> var URL = \"view_comments.php?id=$id\" var speed = 0 function reload(){ location = URL } setTimeout(\"reload()\",speed); </script>"; } else { echo "failed."; } There's no need for an if statement. If $sql fails, it dies on the spot as you have coded above. So there is some redundancy there. Quote Link to comment Share on other sites More sharing options...
fantomel Posted August 25, 2008 Author Share Posted August 25, 2008 Try this: <?php $sql = mysql_query("INSERT INTO `news_comments` (`nid`, `user`, `comment`, `date`, `ip`) VALUES ('$id', '$name', '$comment', '$date', '$ip')") or die(mysql_error()); ?> Also, there are a few other things you may want to know: echo "Some fields left blank. <a href='java script:history.go(-1)'>Try Again</a>"; I don't think you can split the word "javascript" like that. if ($sql) { echo "<script Language=\"JavaScript\"> var URL = \"view_comments.php?id=$id\" var speed = 0 function reload(){ location = URL } setTimeout(\"reload()\",speed); </script>"; } else { echo "failed."; } There's no need for an if statement. If $sql fails, it dies on the spot as you have coded above. So there is some redundancy there. thank you thank you very much very much ur a life savior i'm doing this stuff for a friend trying to help him and i'm not a very good coder u helped me a lot thank you very much Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 25, 2008 Share Posted August 25, 2008 You have incorrect syntex in your insert query it should be insert into table (colmuns) values (data) It's not necessary to specify columns in INSERT statement, but it definetely helps avoiding errors like this one. Quote Link to comment Share on other sites More sharing options...
fantomel Posted August 25, 2008 Author Share Posted August 25, 2008 thank you all for your help Quote Link to comment 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.