By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,045 Members | 2,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,045 IT Pros & Developers. It's quick & easy.

If statement in option dropdown box.

flexsingh
P: 17
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">Update Court Page!</h1>
</head>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<body background="main 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">Please Choose A Court</strong></td>
</tr>
<tr>
<td><form id="form1" name="form1" method="post"><font face="sans-serif, Arial" font color="white">Court 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("fcourt1.php");
//echo $var;
break;
Case "Fcourt2":
require_once("fcourt2.php");
//echo $var;
break;
Case "Bcourt":
require_once("bcourt.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="project"; // Database name
$tbl_name="bcourt"; // 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=$_GET['Member_No'];
$courtno1=$_GET['Court_No'];
$TSN1=$_GET['Time_Slot_No'];


<body background="main 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="updatebcourt_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">Insert Data Into mySQL Database </strong></td>
</tr>
<tr>
<td><font face="sans-serif, Arial" font color="white">Member 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">Court 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">Time 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="project"; // Database name
$tbl_name="court"; // 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=$_POST['Member_No'];
$courtno=$_POST['Court_No'];
$TSN=$_POST['Time_Slot_No'];

// Insert data into mysql
$sql="INSERT INTO $tbl_name(Member_No, Court_No, Time_Slot_No)VALUES('$memberno', '$courtno', '$TSN')";
$result=mysql_query($sql);

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

header('Location: blank.php');
}

else {
echo "ERROR";
}

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

$db_name="project"; // Database name
$tbl_name="bcourt"; // 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=$_POST['Member_No'];
$courtno=$_POST['Court_No'];
$TSN=$_POST['Time_Slot_No'];


// Insert data into mysql
$sql="INSERT INTO $tbl_name(Member_No, Court_No, Time_Slot_No)VALUES('$memberno', '$courtno', '$TSN')";
$result=mysql_query($sql);

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

header('Location: 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
Mar 28 '08 #1
Share this Question
Share on Google+
1 Reply


ronverdonk
Expert 2.5K+
P: 4,258
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
Expand|Select|Wrap|Line Numbers
  1. <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
Mar 28 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.