Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Gez
    Gez is offline
    New Coder
    Join Date
    May 2008
    Posts
    32
    Thanks
    4
    Thanked 0 Times in 0 Posts

    A few questions - abit stuck

    Ok, my code is below but i can't seem to get anything thats going on in the functions ShowRetFlights and ShowDepFlights to appear/work i think it might be something to do with the sessions but im not sure. Also if anyone knows, how should i go about getting the text boxes in the form to keep the vale that was typed in before pressing the submit button?

    Thanks in advance

    <style type="text/css">
    <!--
    body {
    background-image: url(bg.jpg);
    text-align: center
    }
    body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    }
    h1 {
    font-size: xx-large;
    }
    -->
    </style>
    <?php

    session_start();

    Include ("dbconnect.php");

    Function form(){
    echo "
    <form action='".$_SERVER['PHP_SELF']."' method='GET'>
    <table align='center' width='200' border='0'>
    <tr>
    <td align='center'>Destination:</td>
    <td align='center'>Flying from:</td>
    </tr>
    <tr>
    <td><input name='destination' type='text'></td>
    <td><input name='flyfrom' type='text'></td>
    </tr>
    <tr>
    <td align='center'>Date (YYYY-MM-DD)</td>
    <td align='center'>Date (YYYY-MM-DD)</td>
    </tr>
    <tr>
    <td><input name='depdate' type='text'></td>
    <td><input name='retdate' type='text'></td>
    </tr>
    <tr>
    <td colspan='2' align='center'><input type='submit' value='Take me there!'></td>
    </tr>
    </table>
    </form>";
    }

    Function ShowRetFlights (){
    // Set Sessions
    $DestinationName=$_REQUEST['destination'];
    $FlyingFrom=$_REQUEST['flyfrom'];
    $RetDate=$_REQUEST['retdate'];
    // Do the query
    $resultret = mysql_query("SELECT * FROM $table_flight
    WHERE DestinationAirport ='".$FlyingFrom."'
    AND DepartureDate ='".$RetDate."'
    AND DepartureAirport ='".$DestinationName."'");

    return ($resultret);

    echo " <b> INBOUND flights </b> <br/><br/>
    <table align='center' width='200' border='0'>
    <tr>
    <td align='center'>Destination: </td>
    <td align='center'>Airline:</td>
    <td align='center'>Departure Airport:</td>
    <td align='center'>Departure Date:</td>
    <td align='center'>Departure Time:</td>
    <td align='center'>Cost:</td>
    <td align='center'></td>
    </tr>";

    // Display the results
    while ($row = mysql_fetch_array( $resultret )){
    echo "<tr>";
    echo " <td align='center'>".$row['DestinationAirport']."</td>";
    echo " <td align='center'>".$row['Airline']."</td>";
    echo " <td align='center'>".$row['DepartureAirport']."</td>";
    echo " <td align='center'>".$row['DepartureDate']."</td>";
    echo " <td align='center'>".$row['DepartureTime']."</td>";
    echo " <td align='center'>".$row['Fare']."</td>";
    echo " <td align='center'></td>";
    echo " </tr>";
    }
    echo "</table><br/><hr><br>/";
    }



    Function ShowDepFlights (){
    $table_flight="flight";
    // Set Sessions
    $DestinationName=$_REQUEST['destination'];
    $DepDate=$_REQUEST['depdate'];
    $FlyingFrom=$_REQUEST['flyfrom'];
    $RetDate=$_REQUEST['fretdate'];

    // Do the query
    $resultdep = mysql_query("SELECT * FROM $table_flight
    WHERE DestinationAirport ='".$DestinationName."'
    AND DepartureDate ='".$DepDate."'
    AND DepartureAirport ='".$FlyingFrom."'");

    return ($resultdep);

    echo " <b> OUTBOUND flights </b> <br/><br/>
    <table width='200' border='1'>
    <tr>
    <td align='center'>Destination: </td>
    <td align='center'>Airline:</td>
    <td align='center'>Departure Airport:</td>
    <td align='center'>Departure Date:</td>
    <td align='center'>Departure Time:</td>
    <td align='center'>Cost:</td>
    <td align='center'></td>
    </tr>";

    // Display the results
    while ($row = mysql_fetch_array( $resultdep )){
    echo "<tr>";
    echo " <td align='center'>".$row['DestinationAirport']."</td>";
    echo " <td align='center'>".$row['Airline']."</td>";
    echo " <td align='center'>".$row['DepartureAirport']."</td>";
    echo " <td align='center'>".$row['DepartureDate']."</td>";
    echo " <td align='center'>".$row['DepartureTime']."</td>";
    echo " <td align='center'>".$row['Fare']."</td>";
    echo " <td align='center'></td>";
    echo " </tr>";
    }
    echo "</table><br/><hr><br>/";
    }


    echo "
    <html>
    <head>
    <title> Lufbra Travel </title>
    </head>
    <body>
    <h1>Lufbra Travel</h1> ";

    form();

    ShowDepFlights();

    ShowRetFlights();

    echo "
    <hr><br/>
    &copy; Geraint Fisher 2008
    </body>
    </html> ";

    ?>

  • #2
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    By the looks of it I would say remove these two lines:
    return ($resultret); and return ($resultdep);
    These are ending your functions prematurely and returning the query result identifier, which isn't needed.

    I would recommend setting the form method to "POST" instead of "GET" and using $_POST instead of $_REQUEST (this won't fix your problem, but it's good practice).

    To get form fields to keep their submitted values.
    PHP Code:
    <input type="text" name="destination" value="<?php echo isset($_POST['destination']) ? $_POST['destination'] : ''?>" />
    Note that this will only work if you take my recommendation to swap all of your $_REQUEST, to $_POST, otherwise replace $_POST in my code snippet with $_REQUEST.

    Also I would recommend opening your strings with ' instead of ", this allows you to use " in your html tags. Or better yet use HEREDOC syntax.
    Last edited by RMcLeod; 05-14-2008 at 03:33 PM.

  • Users who have thanked RMcLeod for this post:

    Gez (05-14-2008)

  • #3
    Gez
    Gez is offline
    New Coder
    Join Date
    May 2008
    Posts
    32
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thank you RMcLeod that fixed my original problem but now i have the error

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /disks/diskh/zco/cogf/public_html/Planner/flightfinder.php on line 74

    which is
    while ($row = mysql_fetch_array( $resultdep )){

  • #4
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    I'm guessing there's an error in your sql, add or die(mysql_error()) to the end of your sql query to find out what it is.

    Like This:
    PHP Code:
    <?php
    $resultdep 
    mysql_query("SELECT * FROM $table_flight
    WHERE DestinationAirport ='"
    .$DestinationName."'
    AND DepartureDate ='"
    .$DepDate."'
    AND DepartureAirport ='"
    .$FlyingFrom."'") or die (mysql_error());
    ?>

  • #5
    Gez
    Gez is offline
    New Coder
    Join Date
    May 2008
    Posts
    32
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Yup, ive done that and i get the error:

    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 'WHERE DestinationAirport ='Gatwick' AND DepartureDate ='2008-01-08' AND ' at line 2

    i can't see the problem when i compare it to the one that does actully work :/

  • #6
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    I can't see anything wrong with that bit of SQL, replace the 'or die(mysql_error());' with 'or die ($resultdep);' This will give you the entire SQL query as passed to the server, see if you can see any errors in it.

  • #7
    Gez
    Gez is offline
    New Coder
    Join Date
    May 2008
    Posts
    32
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I did that and nothing atall came up, thanks alot anyway.

  • #8
    New Coder
    Join Date
    Mar 2008
    Location
    Somerset, England
    Posts
    93
    Thanks
    0
    Thanked 10 Times in 10 Posts
    My mistake of course it won't. This will work

    PHP Code:
    <?php
    $resultdep 
    "SELECT * FROM $table_flight
    WHERE DestinationAirport ='"
    .$DestinationName."'
    AND DepartureDate ='"
    .$DepDate."'
    AND DepartureAirport ='"
    .$FlyingFrom."'";

    mysql_query($resultdep) or die ($resultdep);
    ?>


  •  

    Posting Permissions

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