Jump to content

[SOLVED] Column count doesn't match value count at row 1 please help


fantomel

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.