473,657 Members | 2,535 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">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
Mar 28 '08 #1
1 2556
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
5163
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 error an needs to be posted in the javaScript newsgroup. The FireFox javaScript Console reports the following message: Error: missing : in conditional expression Source Code: location.href=themes.php?scheme=(form.color_schemes.options.value)
5
3874
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 in the select statement the color only applies to the undroppeddown menu. When opened the color disappears. In the option statement it has no effect. I have tried IE and Netscape on a Mac.
2
1432
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 item to be loaded into the db. All I can get in the database is the first part of their name upto the first space ? i.e. if the selected item from the dropdown is A B Knowles, the database entry is 'A'
1
3456
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 set of 3 dropdown boxes be filled with the same values. thank you <head> <SCRIPT LANGUAGE="JavaScript" type="text/javascript"> var firstChoice2 = 0; var secondChoice2 = 0;
0
8413
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7352
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.