SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: New code error!

  1. #1
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New code error!

    There is an error with the while on the 4th line of code below. It's a syntax error saying that "unexpected T_LOGICAL_OR in /home/a3362820/public_html/assignment/index.php"

    <?php

    echo "<h1>Blog</h1><hr>";

    require_once('includes/config.php');

    $queryget = mysql_query("SELECT * FROM blogEntries ORDER BY id DESC");

    while ($row = mysql_fetch_assoc($queryget)) or die (mysql_error())
    {
    $id = $row['id'];
    $name = $row['name'];
    $message = $row['message'];
    $date = $row['date'];
    $time = $row['time'];
    }

    echo "<hr>";

    echo "
    <form action=;index.php' method='POST'>
    <table width='100%'>
    <tr>
    <td width='18%' valign='top'>
    Your name:
    </td>
    <td>
    <input type='text' name='name' maxlength='25'>
    </td>
    </tr>

    <tr>
    <td valign='top'>
    Your message:
    </td>
    <td>
    <textarea cols='20' rows='2' name='message maxlength='250'>
    <p>
    <input type='submit' name='submit' value='Post'>
    </td>
    </tr>
    </table>
    </form>

    ";
    ?>

    Any help would be appreciated.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,491
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Please use the appropriate tags when you post code.

    And why do you use 'or die' here?
    Code:
    while ($row = mysql_fetch_assoc($queryget)) or die (mysql_error())
    Use it on the mysql_query command instead.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This line is not correct syntax:
    PHP Code:
    while ($row mysql_fetch_assoc($queryget)) or die (mysql_error())

    You need to remove the or die (mysql_error())" bit.

  4. #4
    SitePoint Zealot Amit Yaron's Avatar
    Join Date
    Jan 2011
    Location
    Hod Haharon, Israel
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't add any code between the closing ')' of the while condition and the '{'.
    Rewriting the while sentence ...
    Code:
    while ($row = mysql_fetch_assoc($queryget) or die(mysql_error()))

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    To be honest you should not be using "or die()" in the first place.
    Implement proper error handling from the beginning.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •