SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Return Results error

    Hello all, I am trying to build a query that a user can do by selecting something in a drop-down box. I am getting a "line 1" syntax error though on the return results code. Can someone check out the code for obvious errors please and reply with any ideas on how to write if correctly?

    Here is the code for the select form with the drop-down box that seems to work fine.

    PHP Code:
    <form action="driverraceresults.php" method="post">
    <table cellpadding="0" cellspacing="5" border="0" width="450">
    <tr><td class="scheduleheader">View a driver's Race Results</td></tr>
    <tr><td> 
    <?php
    $sql 
    "SELECT Driver FROM season04 ORDER by Driver ASC";
    $results mysql_query($sql);
    print(
    "<select width=\"150\" style=\"width: 150px\" name=\"select\">\n" );
    while (
    $row mysql_fetch_array($results)):
    $name $row["Driver"];
    print(
    "<option value=\"$name\">$name\n" );
    endwhile;
    print(
    "</select>\n" );
    ?> 
    </td><tr>
    <td align="center"><br /><input class="lefttext" type="submit" name="submit" value="Submit"></td>
    </tr> 
    </table>
    </form>

    Here is the code for the return results page as listed in the "action" for the form up above:

    PHP Code:
    print"<table class=\"userstats\" border=\"1\" style=\"width:85%;\">
    <tr class=\"scheduleheader\"><td>Finish</td><td>Start</td><td>Car#</td><td>Driver</td><td>Interval</td><td>Laps</td><td>Led</td>
    <td>Pts</td><td>Status</td></tr>"
    ;
    $query=" SELECT * FROM nc04, lv04, atl04 WHERE Driver = " .$_REQUEST['select'];
    $result=mysql_query($query);
    if (!
    $result) { 
    echo(
    "<p>Error performing query: " mysql_error() . "</p>" ); 
    exit(); 
    }
    if (
    $row = @mysql_fetch_array($resultMYSQL_ASSOC)) {
    print
    "<tr class=\"scheduledata\"><td>$row[Finish]</td><td>$row[Start]</td><td>$row[Car_Number]</td><td>$row[Driver]</td>
    <td>
    $row[Interval_Difference]</td><td>$row[Laps]</td><td>$row[Led]</td><td>$row[Points]</td><td>$row[Status_End]</td></tr>";
    }
    print
    "</table>";
    ?> 
    I am new to this type of function so please be gentle, lol

    Thank you, Troy

  2. #2
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php
    while ($row = mysql_fetch_array($results)):
    $name = $row["Driver"];
    print("<option value=\"$name\">$name\n" );
    endwhile;
    ?> 

    I don't believe you can access an array index in this manner: $name = $row["Driver"]; without using mysql_fetch_assoc() instead of mysql_fetch_array. Don't quote me on that, but try using fetch_assoc instead of fetch_array
    Ryan

  3. #3
    SitePoint Addict -Ice-php's Avatar
    Join Date
    May 2002
    Location
    UK
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    $name = array();
    $max = mysql_num_rows($results);
    while ($row = mysql_fetch_array($results)):
    $name[] = $row["Driver"];
    endwhile;


    for($i = 0; $i<$max; $i++){
    echo "<option value=\"$name[$i]\">$name[$i]\n";
    }

    Im not quite sure but the while statement just keeps replaces each <option> statement
    just try it and see what happens :S


    ?>
    -Ice

  4. #4
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guys, thanks for the replies. The problem is not with the drop-down at all. It passes fine. I only put it up for reference. The problem is the return results coding.

    somewhere in here:

    $query=" SELECT * FROM nc04, lv04, atl04 WHERE Driver = " .$_REQUEST['select'];

    I am getting the error.

  5. #5
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, if there is a Driver name in the database with an * or other html special characters, how do I escape it in the submit form?

  6. #6
    SitePoint Addict Knightime's Avatar
    Join Date
    Jan 2003
    Location
    USA
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone have an idea how to troubleshoot or fix the error?

  7. #7
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Knightime
    Anyone have an idea how to troubleshoot or fix the error?
    If you feel this line is giving the error:

    $query=" SELECT * FROM nc04, lv04, atl04 WHERE Driver = " .$_REQUEST['select'];

    Then try this:

    $query = "SELECT * FROM nc04,lv04,atl04 WHERE Driver = $_REQUEST[select]";

    Since the query is in double quotes it will still read $_REQUEST[select]

    P.S. Add single quotes around $_REQUEST[select] if it isnt a number

    Silly


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
  •