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

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.

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

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.

Archived

This topic is now archived and is closed to further replies.

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