Jump to content
Larry Ullman's Book Forums

walt

Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by walt

  1. MySQL Version: 5.0.45

    PHP Verson: 5.2.17

     

    I am using a code modified from chapter 17.

    but I cannot get mysql to display query results using php.

    I made a page to make a summary (title and date only) page that turns the title into a link to the detailed page

    it is working correctly

     

    when i click on entry #4 (all work the same way) for example my url seems to be correct

     

    ...blogpage.php?pid=4

     

    but I get this result at the top of the resulting page

     

    SELECT entry_id , title , date_updated , p1 , p2, FROM blog WHERE entry_id = 1

    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in **redacted**walterlovett/htdocs/cityofwinfield/blogpage.php on line 15 (shows as row 10 in the inserted code (while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {)

     

    this is my mysql table structure

     

    entry_id int(5) No (auto increments)

    date_updated timestamp No CURRENT_TIMESTAMP (auto updates)

    title varchar(40) No Entry Title (default text)

    p1 text No

    p2 text No

     

    PRIMARY entry_id

     

     

     

    here is my code

     

    <?php
    // This page displays the details of the post.
    $row = FALSE; // Assume nothing!
    if (isset($_GET['pid']) && is_numeric($_GET['pid']) ) { // Make sure there's an entry ID!
     $pid = (int) $_GET['pid'];
    // Get the post info:
    require_once ('../../mysqli_connect_city_of_winfield.php');
    echo $q = "SELECT entry_id , title , date_updated , p1 , p2, FROM blog WHERE entry_id = $pid";
    $r = mysqli_query ($dbc, $q);
    while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {
    // Fetch the information:
    $row = mysqli_fetch_array ($r, MYSQLI_ASSOC);
    // Start the HTML page:
    $title='Unit Details';
    include('includetop.html');
    echo "<p>{$row['title']}</p>";
    echo "<p>{$row['date_updated']}</p>";
    echo "<p>{$row['p1']}</p>";
    echo "<p>{$row['p2']}</p>";
    } // End of the mysqli_num_rows() IF.
    mysqli_close($dbc);
    }
    if (!$row) { // Show an error message.
    include('includetop.html');
    echo '<h1>Error 404; File Not Found<br></br>
    The page you are looking for has most likely been upgraded, <br></br>
    please use the  navigation at the left to find what you need,<br></br>
    Thanks.</h1>';
    }
    // Complete the page:
    include('includefooter.html');
    ?>
    

     

     

     

    when the page is called i get the "else" option (my little 404 message in the code above) and this is printed at the top of the page (i just put the echo of the query in there to help me debug)

     

    SELECT entry_id , title , date_updated , p1 , p2, FROM blog WHERE entry_id = 1

    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in **redacted**walterlovett/htdocs/cityofwinfield/blogpage.php on line 15(shows as row 10 in the inserted code (while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {)

     

    when i run that query in mysql phpadmin i get this response from mysql

     

    Error

    SQL query:

    SELECT entry_id, title, date_updated, p1, p2,

    FROM blog

    WHERE entry_id =4

    LIMIT 0 , 30

    MySQL said:

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM blog WHERE entry_id = 4 (the 4 just happens to be the entry i clicked on)

    LIMIT 0, 30' at line 1

     

    I really can not see what is wrong with my syntax.

    Any help would be greatly apprecitated

     

    walt

×
×
  • Create New...