473,503 Members | 2,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If statement in option dropdown box.

flexsingh
17 New Member
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
1 2541
ronverdonk
4,258 Recognized Expert Specialist
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

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

Similar topics

1
5153
by: Michelle | last post by:
I have tried every variation of the "onchange" statement below without any actual reloading of the page. I am hoping that the PHP PRINT statement is constructed wrong, otherwise it is javaScript...
5
3869
by: Dennis M. Marks | last post by:
Please look at page http://www.dcs-chico.com/~denmarks/amtrak.html I am trying to change the color of the first dropdown menu but everything that I have tried has no effect. If I put the style...
2
1425
by: David | last post by:
Hi, I have an asp page which runs an update into our mysql database. The only problem I have is that a user selects a customer from a dropdown (this is database fed), and I require the selected...
1
3448
by: bytesFTW99 | last post by:
I have been struggling with this for some time can anyone help out? just trying to have 3 dropdown boxes that fill depending on what is selected, then in some cases click a button and have the second...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.