Welcome to Laser Pointer Forums - discuss green laser pointers, blue laser pointers, and all types of lasers

Buy Site Supporter Role (remove some ads) | LPF Donations

Links below open in new window

FrozenGate by Avery

PHP Help?

Joined
Jan 20, 2010
Messages
81
Points
0
I'm curious if anybody knows php here.. I'm currently having some problems with some simple code and I can't figure out why it's not functioning as it should be. If anybody knows anything about php I'll post the code.

Chris
 





I'd be happy to help, post what you've got and what errors you're getting. :)

-Trevor
 
Ok :)

Heres the code:

Code:
<html>
<head>
</head>
<body>

<center>
	<h1>Local Drug Price</h1>
<br>
<?php
$country = $_GET['country'];
echo $country;
?>
<br>
<div>
	<form name="location" action="index.php" method="get">
		<table>
			<tr>
				<td>
					Country
				</td>
					<?php
						if (isset($country)) {
					?>
				<td>
					State/Province
				</td>
					<?php
						}
						if (isset($_GET['stateprovince'])) {
					?>
				<td>
					City
				</td>
					<?php
						}
					?>
			</tr>
			<tr>
				<td>
				<select name=country>
					<option <?php if ($country = ""){ echo "selected"; }?>></option>
					<option value=CAN <?php if ($country == "CAN"){ echo "selected"; }?>>Canada</option>
					<option value=USA <?php if ($country == "USA"){ echo "selected"; }?>>USA</option>
				</select>
				</td>
					<?php
							if (isset($country)) {
					?>
				<td>
				<select name=stateprovince>
				</select>
				</td>
					<?php
						}
						if ($_GET['stateprovince']) {
					?>
				<td>
				<select name=city>
				</select>
				</td>
					<?php
						}
					?>
			</tr>
		</table>
		<BR>
		<input type=submit value=Submit>			
	</form>
</div>
</center>
</body>
</html>


It's really quite simple. What's suppose to happen is the country menu is to only show when the page first pops up. And then when you submit each submenu the next one shows up and the last menu retains it's selected value. What is happening is this: http://www.thekrash.com/chris/localdrugcost/
And I can't find anything logically that would make it do that. :s so I'm stuck where I am.

Note that I'm echoing the get value for debug purposes.
 
I changed it to use the post method; that will be easier for this. Some of it was faulty HTML coding (i.e. name=city rather than name="city", and "selected" rather than "selected="selected"). Also, the comparison operator for equality is "==", not "=". When you put an assignment in an if statement, it will always return true.

I also kept your writing style. Here's a modified version, and a demo of it working:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Local Drug Price</title>
</head>

<body>

<center>
	<h1>Local Drug Price</h1>
<br>
<?php
//$country = $_GET['country'];
//echo $country;
?>
<br>
<div>
	<form name="location" action="index.php" method="post">
		<table>
			<tr>
				<td>
					Country
				</td>
					<?php
						if (isset($_POST['country'])) {
					?>
				<td>
					State/Province
				</td>
					<?php
						}
						if (isset($_POST['stateprovince'])) {
					?>
				<td>
					City
				</td>
					<?php
						}
					?>
			</tr>
			<tr>
				<td>
				<select name="country">
					<option <?php if ($_POST['country'] == ""){ echo "selected=\"selected\""; }?>></option>
					<option value="CAN" <?php if ($_POST['country'] == "CAN"){ echo "selected=\"selected\""; }?>>Canada</option>
					<option value="USA" <?php if ($_POST['country'] == "USA"){ echo "selected=\"selected\""; }?>>USA</option>
				</select>
				</td>
					<?php
							if (isset($_POST['country'])) {
					?>
				<td>
				<select name="stateprovince">
                	<?php
							if ($_POST['country'] == "USA") {
					?>
                    	<option <?php if ($_POST['stateprovince'] == ""){ echo "selected=\"selected\""; }?>></option>
                        <option value="VA" <?php if ($_POST['stateprovince'] == "VA"){ echo "selected=\"selected\""; }?>>Virginia</option>
                    <?php
							}
							if ($_POST['country'] == "CAN") {
					?>
                    	<option <?php if ($_POST['stateprovince'] == ""){ echo "selected=\"selected\""; }?>></option>
                        <option value="VAN" <?php if ($_POST['stateprovince'] == "VAN"){ echo "selected=\"selected\""; }?>>Vancouver</option>
                    <?php
							}
					?>
				</select>
				</td>
					<?php
						}
						if ($_POST['stateprovince']) {
					?>
				<td>
				<select name="city">
				</select>
				</td>
					<?php
						}
					?>
			</tr>
		</table>
		<br />
		<input type="submit" value="Submit">			
	</form>
</div>
</center>
</body>
</html>

Local Drug Price

-Trevor
 
I guess starting off sloppy and cleaning it up after doesn't work sometimes :P
Thanks a bunch for the help! :)
 





Back
Top