MySQL PHP SELECT throwing up an error?

Posted by user1909695 on Stack Overflow See other posts from Stack Overflow or by user1909695
Published on 2012-12-17T10:57:20Z Indexed on 2012/12/17 11:03 UTC
Read the original article Hit count: 259

Filed under:
|
|
|
|

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++;
    }
    ?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql