Jump to content

Default displaying problem


zang8027

Recommended Posts

So i have a page with 3 drop down menus. Each menu's values are recieved from a database. When you select the first value, it reloads the page and displays the proper values in the dropdown below it. Then that happens again. The problem I am having is that because my drop downs are not getting values until the one above it is selected, I am getting:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MYSQL result.

 

 

Is there like a if(null) statement I can use to set the default value to something like "Please Select a  State"?

 

 

<FORM action="findrestaurants.php" method="POST">
<SELECT NAME="stateList" onChange="this.form.submit()">
<OPTION>Please Select a State
<?php
//Make a connection to the server... connect("servername","username","password")
$link=mysql_connect("localhost","root") or die("No server connection".mysql_error());
//connect to our database
$db=mysql_select_db("dineonline_db") or die("No Database Connection ".mysql_error());
//construct a SQL query that shows all hotels in the city
$query="SELECT * FROM states";
//run the query
$result=mysql_query($query);	

//for each row returned by our query, do what is in curly braces
while($row = mysql_fetch_array($result)){

//store into a variable the ID # for the current row 
$stateID=$row['state_ID'];
//store into a variable the Name for the current row
$stateName=$row['state_name'];
  
//Print out each "<OPTION> with the proper values
print "<OPTION VALUE='$stateID'>$stateName";
}
//close the connection
mysql_close($link);

?>
</SELECT>
</FORM>

<!-- Below is the cityBig List drop down code -->

<FORM action="findrestaurants.php" method="POST">
<SELECT NAME="cityLargeList" onChange="this.form.submit()">
<OPTION>Please Select an Area
<?php
//Get the value from City Large
$userState = $_POST['stateList'];
//Make a connection to the server... connect("servername","username","password")
$link=mysql_connect("localhost","root") or die("No server connection".mysql_error());
//connect to our database
$db=mysql_select_db("dineonline_db") or die("No Database Connection ".mysql_error());
//construct a SQL query that shows all hotels in the city
$query="SELECT * FROM cityLarge WHERE state_ID = $userState";
//run the query
$result=mysql_query($query);	

//for each row returned by our query, do what is in curly braces
while($row = mysql_fetch_array($result)){

//store into a variable the ID # for the current row 
$cityLargeID=$row['cityLarge_ID'];
//store into a variable the Name for the current row
$cityLargeName=$row['cityLarge_name'];
  
//Print out each "<OPTION> with the proper values
print "<OPTION VALUE='$cityLargeID'>$cityLargeName";

}
//close the connection
mysql_close($link);

?>
</SELECT>
</FORM>

<!-- Below is the citySmall List drop down code -->
<FORM action="displayRest.php" method="get">
<SELECT NAME="citySmallList">
<OPTION>Please Select a City
<?php
//Get the value from City Large
$userCityLarge = $_POST['cityLargeList'];
//Make a connection to the server... connect("servername","username","password")
$link=mysql_connect("localhost","root") or die("No server connection".mysql_error());
//connect to our database
$db=mysql_select_db("dineonline_db") or die("No Database Connection ".mysql_error());
//construct a SQL query that shows all hotels in the city
$query="SELECT * FROM citySmall WHERE cityLarge_ID = $userCityLarge";
//run the query
$result=mysql_query($query);	

//for each row returned by our query, do what is in curly braces
while($row = mysql_fetch_array($result)){

//store into a variable the ID # for the current row 
$citySmallID=$row['citySmall_ID'];
//store into a variable the Name for the current row
$citySmallName=$row['citySmall_name'];
  
//Print out each "<OPTION> with the proper values
print "<OPTION VALUE='$citySmallID'>$citySmallName";

}
//close the connection
mysql_close($link);

?>
</SELECT>
<br/>
<br/>
<input type="submit" value="Find restaurants" />
</FORM>

Link to comment
Share on other sites

Now i added this:

 

<?php
//Get the value from City Large

$userState = $_POST['stateList'];
if(isset($userState))
	{
//Make a connection to the server... connect("servername","username","password")
$link=mysql_connect("localhost","root") or die("No server connection".mysql_error());
//connect to our database
$db=mysql_select_db("dineonline_db") or die("No Database Connection ".mysql_error());
//construct a SQL query that shows all hotels in the city
$query="SELECT * FROM cityLarge WHERE state_ID = $userState";
//run the query
$result=mysql_query($query);	

//for each row returned by our query, do what is in curly braces
while($row = mysql_fetch_array($result)){

//store into a variable the ID # for the current row 
$cityLargeID=$row['cityLarge_ID'];
//store into a variable the Name for the current row
$cityLargeName=$row['cityLarge_name'];
  
//Print out each "<OPTION> with the proper values
print "<OPTION VALUE='$cityLargeID'>$cityLargeName";
	}else{

	}

}
//close the connection
mysql_close($link);

?>

 

And i get

 

Unexpected T_ELSE on line 76.

 

If i delete the else part, i get the drop down boxes again but i get:

mysql_close():2 is not a valid MYSQL-Link

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.