MySQL PHP SELECT throwing up an error?
- by user1909695
I am trying to make a comment section on my hand made site, using PHP and MySQL. I have got the comments stored in my database, but when I try to SELECT them my site throws up this error,
mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 9 in /home/a9210109/public_html/comments.php on line 16
My code so far is below
<?php
$comment = $_POST['comment'];
$mysql_host = "";
$mysql_database = "";
$mysql_user = "";
$mysql_password = "";
mysql_connect($mysql_host,$mysql_user,$mysql_password);
@mysql_select_db($mysql_database) or die( "Unable to select database");
$CreateTable = "CREATE TABLE comments (comment VARCHAR(255), time VARCHAR(255));";
mysql_query($CreateTable);
$UseComment = "INSERT INTO comments VALUES ('$comment')";
mysql_query($UseComment);
$SelectComments = "SELECT * FROM comments";
$comments = mysql_query($SelectComments);
$num=mysql_numrows($comments);
$variable=mysql_result($comments,$i,"comment");
mysql_close();
?>
<a href="#" onclick="toggle_visibility('hidden');">Show/Hide Comments</a>
<?php
$i=0;
while ($i < $num) {
$comment=mysql_result($comments,$i,"comment");
echo "<div id='hidden' style='display:none'><h3>$comment</h3></div>";
$i++;
}
?>