If statement in option dropdown box.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flexsingh
    New Member
    • Mar 2008
    • 17

    If statement in option dropdown box.

    Hello there I have kinda got gotten myself into a sticky situation. I am trying to do something which seams too big to do in my head but I feel I kinda know how to do it.

    My problem is I have a website and and users come in and book a court. There are three courts, and on the first page ill have up its a table which they choose which court they want then they go to a new page which is also a table.

    The second page has three values to fill in on the form, the first is the member no, the second is the court which is already defaulted to the court and the final is the time slot. I wish to have the time slot number in a drop down option box where there should be a if statment saying if in the court table member number is blank or "" then print out all the time slots(where member no is blank). It should hide the rest.

    The third and final table is just used to update the information into the table and replace the timeslot and court with the new time slot, court and member number.

    I hope I have explained my self enough if not i will try again sorry.

    Code for the first page (choosing court)

    [HTML]<html>
    <br>
    <br>
    <head>
    <h1><font face="sans-serif, Arial" font color="white">U pdate Court Page!</h1>
    </head>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <body background="mai n background1.jpg " link="blue" vlink="blue">
    <table width="350" border="0" align="center" cellpadding="0" cellspacing="1" >
    <tr>
    <td>
    <table width="100%" border="0" cellspacing="1" cellpadding="3" >
    <tr>
    <td colspan="3" align="center"> <strong><font face="sans-serif, Arial" font color="white">P lease Choose A Court</strong></td>
    </tr>
    <tr>
    <td><form id="form1" name="form1" method="post">< font face="sans-serif, Arial" font color="white">C ourt No</td>
    <td><font color="white">: </td>
    <td><select name="court" id="court">
    <option>-----------------------</option>
    <option value="Fcourt1" >Football court 1</option>
    <option value="Fcourt2" >Football court 2</option>
    <option value="Bcourt"> Basketball court </option>
    </select>
    <input type="submit" name="Submit" value="Submit"/>
    </form>
    </td>
    </tr>
    </table>
    <?php
    if($_SERVER['REQUEST_METHOD '] == 'POST')
    {
    $court = $_POST['court'];
    switch ($court)
    {
    case "Fcourt1":
    require_once("f court1.php");
    //echo $var;
    break;
    Case "Fcourt2":
    require_once("f court2.php");
    //echo $var;
    break;
    Case "Bcourt":
    require_once("b court.php");
    //echo $var;
    break;
    }
    }
    ?>
    </body>
    </html> [/HTML]

    Code for second page the if statement

    [PHP]<?php
    // this starts the session
    session_start() ;
    ?>

    <html>
    head>
    </head>

    <?php
    $db_name="proje ct"; // Database name
    $tbl_name="bcou rt"; // Table name


    // Connect to server and select database.
    mysql_connect($ _SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
    mysql_select_db ("$db_name") or die("cannot select DB");

    // Get values from form
    $memberno1=$_GE T['Member_No'];
    $courtno1=$_GET['Court_No'];
    $TSN1=$_GET['Time_Slot_No'];


    <body background="mai n background1.jpg " link="blue" vlink="blue">

    <table width="350" border="0" align="center" cellpadding="0" cellspacing="1" >
    <tr>
    <td><form name="Update Network Gaming form" method="post" action="updateb court_ac.php">
    <table width="100%" border="0" cellspacing="1" cellpadding="3" >
    <tr>
    <td colspan="3" align="center"> <strong><font face="sans-serif, Arial" font color="white">I nsert Data Into mySQL Database </strong></td>
    </tr>
    <tr>
    <td><font face="sans-serif, Arial" font color="white">M ember No</td>
    <td><font color="white">: </td>
    <td><input name="Member_No " type="int" id="Member_No"> </td>
    </tr>
    <tr>
    <td><font face="sans-serif, Arial" font color="white">C ourt No</td>
    <td><font color="white">: </td>
    <td><input name="Court_No" type="varchar" id="Court_No" value="Bcourt"> </td>
    </tr>
    <tr>
    <td><font face="sans-serif, Arial" font color="white">T ime Slot No</td>
    <td>:</td>
    <td><select value="please choose a Date" name="Time_Slot _No" size="1" >
    if ( 'Member_No' == ""){

    //<option value=$rows['Time_Slot_No']</option>
    <option value=$TSN1</option>
    }
    </select></td>
    </tr>

    <td colspan="3" align="center"> <input type="submit" name="Submit" value="Continue "></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>


    // close connection
    mysql_close();
    ?>
    </body>
    </html>[/PHP]

    The final page which works fine. Just showing incase you need to see the code.

    [PHP]<?php
    // this starts the session
    session_start() ;
    ?>
    <?php
    $db_name="proje ct"; // Database name
    $tbl_name="cour t"; // Table name

    // Connect to server and select database.
    mysql_connect($ _SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
    mysql_select_db ("$db_name") or die("cannot select DB");

    // Get values from form
    $memberno=$_POS T['Member_No'];
    $courtno=$_POST['Court_No'];
    $TSN=$_POST['Time_Slot_No'];

    // Insert data into mysql
    $sql="INSERT INTO $tbl_name(Membe r_No, Court_No, Time_Slot_No)VA LUES('$memberno ', '$courtno', '$TSN')";
    $result=mysql_q uery($sql);

    // if successfully insert data into database, displays message "Successful ".
    if($result){

    header('Locatio n: blank.php');
    }

    else {
    echo "ERROR";
    }

    // close connection
    mysql_close();
    ?>
    <?php

    $db_name="proje ct"; // Database name
    $tbl_name="bcou rt"; // Table name

    // Connect to server and select database.
    mysql_connect($ _SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
    mysql_select_db ("$db_name") or die("cannot select DB");

    // Get values from form
    $memberno=$_POS T['Member_No'];
    $courtno=$_POST['Court_No'];
    $TSN=$_POST['Time_Slot_No'];


    // Insert data into mysql
    $sql="INSERT INTO $tbl_name(Membe r_No, Court_No, Time_Slot_No)VA LUES('$memberno ', '$courtno', '$TSN')";
    $result=mysql_q uery($sql);

    // if successfully insert data into database, displays message "Successful ".
    if($result){

    header('Locatio n: blank.php');
    }

    else {
    echo "ERROR";
    }

    // close connection
    mysql_close();
    ?>[/PHP]

    I have tried to get the vale to go in the option section two ways but I need it to like show al data. Is the task too big?

    Thank you for any advice in advanced. Looks challenging :D
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Just looking at the code, e.g. script 2 leaves some questions that have to be asked before we can move on.

    For instance: you mix php and html without changing tags, see statement 22-25, 51, 64-65. You must have had some errors in your IDE!

    Then, what are you doing with mySQL after this statement:[php]mysql_select_db ("$db_name") or die("cannot select DB");[/php]Did you mean to execute a query and fill the drop down? The MySQL statements in script 2 are no use like this.

    In your statement 51 you use (within a html statement) a PHP variable that has been loaded from a $_GET entry. The form you submit in script 1 is a POST, so what is statement 51 doing? And you will only fill one option statement. And that cannot succeed because that statement is rendered as
    Code:
    <option value=value</option>
    In short, there are a lot of syntax errors and mixing of diffferent types of code in your script (and until now I am only talking about script 2).

    So you better clean that up first and then we can see what the real problem is.

    Ronald

    Comment

    Working...