Guestbook - No Error messages nor outcome

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • infoseekar
    New Member
    • Mar 2008
    • 34

    Guestbook - No Error messages nor outcome

    HI Guys

    I am a beginner.
    I am trying to create a guestbook. I have the code for it and it is in three parts. Part 1 "dp.php" to open database and make connection Part 2 "index.php" which will show the guestbook entries and Part 3 "add.php" to add new entry.

    The problems is when i run any of the file nothing happens i.e. no error(s) and no result.

    I tired to check the code so many times and couldnt any find any errors.

    Part 1

    [code=php]
    <?php

    $user="user";
    $host="localhos t";
    $password="pass word";
    $database = "test";

    $connection = mysql_connect($ host,$user,$pas sword) //open connection to MySQL
    or die ("couldn't connect to server");


    $db = mysql_select_db ($database,$con nection) // open session to Database
    or die ("Couldn't select database");

    mysql_select_db ("$db", $connection);
    ?>
    [/code]

    Part 2

    [code=php]

    <?php

    ****$sql*=*"SEL ECT text*FROM*guest book*ORDER*BY*i nsertdate*DESC" ;
    ****$result*=*m ysql_query($sql );
    ?>

    <html>
    <body>
    ****<a href="add.php"> Add*a*comment</a>
    ****<h1>Guestbo ok</h1>
    ****<br/><table>****
    <?php*while*($r ow*=*mysql_fetc h_assoc($result ))*{*?>
    *********<tr><t h><?php*echo*$r ow['name']."*-*".$row['insertdate'];*?></th></tr>
    *********<tr><t d><?php*echo*nl 2br($row['text']);*?></td></tr>
    <?php*}*?>
    ****</table>****
    </body>
    </html>
    [/code]

    Part 3

    [code=php]

    <?php

    include 'dp.php';

    if (isset($_POST['submitBtn']))
    {
    $name = (isset($_POST['name'])) ? addslashes(html entities($_POST['name'])) : '' ;
    $comment = (isset($_POST['comment'])) ? addslashes(html entities($_POST['comment'])) : '' ;
    $actDate = date("d-m-Y H:i:s");

    //Minimum name and comment length.
    if ((strlen($name) > 2) && (strlen($commen t) > 5))
    {
    $sql = "INSERT INTO guestbook (name,text,inse rtdate) VALUES ('$name','$comm ent','$actDate' )";
    mysql_query($sq l);
    }

    header("Locatio n: index.php");
    }
    else {

    ?>

    <html>
    <body>
    <h1>Add comment</h1>
    <form action= method="post" name="gbook">
    <table>
    <tr><th>Name: </th><td><input type="text" name="name" id="name"/></td></tr>
    <tr><th>Comment :</th>
    <td><textarea name="comment" cols=30 rows=5></textarea></td>
    </tr>
    <tr><td colspan="2" align="center">
    <input type="submit" name="submitBtn " id="submitBtn" value="Add comment"/></td>
    </tr>
    </table>
    </form>
    </body>

    <?php } ?>

    </html>
    [/code]

    Thanks in Advance

    Regards
    Zeshan
    Last edited by infoseekar; Jul 25 '08, 11:44 AM. Reason: Code Tag
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    First let's make sure your code for connecting to the database works. Put some echo statements to tell us what is happening. Specifically put an echo at the end saying something like "Database connection successful".

    Comment

    • infoseekar
      New Member
      • Mar 2008
      • 34

      #3
      Originally posted by r035198x
      First let's make sure your code for connecting to the database works. Put some echo statements to tell us what is happening. Specifically put an echo at the end saying something like "Database connection successful".
      Thanks for replying.

      Code for connecting to the database works. It echo Database connection successful. Now bit of "index.php" works. I can see a link for Add comment page and heading "Guestbook" . On the same page (index.php) I should be able to see a form as well but i dont see nothing and "add.php" doesnt work at all i.e. no error messages.

      Thanks

      EDIT: ERROR: UNEXPECTED T_VARIABLE IN LINE 3 (INDEX.PHP)
      Last edited by infoseekar; Jul 25 '08, 02:05 PM. Reason: ERROR FOUND

      Comment

      • infoseekar
        New Member
        • Mar 2008
        • 34

        #4
        UNEXPECTED T_VARIABLE ERROR IN LINE 3 (INDEX.PHP) IS SOLVED.

        BUT I still dont see the form.

        thanks

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi.

          The second mysql_select_db call in Part1 is most likely causing problems.
          You are assigning the boolean return value from the first one to a variable, and then passing that to the second one.

          Try removing the second call all together and see what happens.

          And btw... what's up with all the * chars in Part2?

          Comment

          Working...