pls help i am beginner and i am trying to create a simple Guestbook but i got error

"Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /index.php on line 43"

here is the code i use :

    require ($_SERVER["DOCUMENT_ROOT"]."/komara/config/db_config.php");
    $connection = @mysql_connect($db_host, $db_user, $db_password) or die ("error connecting");
    mysql_select_db($db_name, $connection);

    $name = $_POST["txt_name"];
    $len = strlen($name);
    //only write to datebase if there's a name
    if ($len > 0)

        $email = $_POST["txt_email"];
        $comment = $_POST["txt_comment"];
        $date = time();

        $query = "INSERT INTO guest (autoID, name, email, comment, date_auto) VALUES (NULL, '$name', '$email', '$comment', '$date')";
        mysql_query($query, $connection) or die(mysql_error());

    <title> Guestbook Komara </title>
<form action="<?php echo $_SERVER[PHPH_SELF]; ?>" method="POST">
    <font face="arial" size="1">
        Name: <input type="text" name="txt_name" >&nbsp;
        Email: <input type="text" name="txt_email"><br><br>
        <textarea style="width:75%" rows=10 name="txt_comment"></textarea>
        <center><input type="submit" value="Submit"></center>

<table bgcolor="AAAAAA" border="0" width="75%" cellspacing=1"1" cellpading="2">
    $query = "SELECT * FORM guest ORDER BY date_auto";
    $result = mysql_query($query, $connection);

    for ($i = 0; $i < mysql_num_rows($result); $i++) [COLOR="red"][B]// here is line 43[/B][/COLOR]
        $name = mysql_result($result, $i, "name");
        $email = mysql_result($result, $i, "email");
        $email_len = strlen($email);
        $comment = mysql_result($result, $i, "comment");
        $date = mysql_result($result, $i, "date_auto");
        $show_date = date("H:i:s m/d/Y", $date);

        echo '
              <td width="50%" bgcolor="#EEEEEE">
                <font face="arial" size="2">';
                  if ($email_len > 0)
                    echo '<b>Name:</b> <a href="mailto:'.$email.'>"'.$name.'</a>';
                  echo '<b>Name:</b> '.$name;
                  echo '
                  <b>Comment:</b> '.$comment.'
                 <td width="1%" valign="top" nowrap bgcolor="#EEEEEE">
                  <font face="arial" size="2">
                   <b>Date:</b> '.$show_date.'


Edited by Nick Evan: Fixed formatting

6 Years
Discussion Span
Last Post by pritaeas

Your query is wrong, typo in FROM. Also read the sticky thread in this forum on how to find out what is wrong.


omg thanks it was realy a simple mistake :) thank you pritaeas, about that sticky thread where it is ?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.