Thanks guys.
I changed my code around a bit. now I have a database of States and the the colleges in them. I want a user to select the state via a drop down menu. Then when the user goes to select a college, they are presented with only the colleges that correspond to that state.
My problem is that I can't figure out the syntax to get the colleges to appear in a drop down menu without getting errors.
Here is the error message I get:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\Drop.php on line 49
(The error refers to the PHP code)
This is my HTML code:
Code: Select all
<!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>Untitled Document</title>
</head>
<body>
select your state:
<form action="Drop.php" method="post">
<select name="State">
<option value="NY">NY</option>
<option value="ND">ND</option>
</select>
<input type="submit" />
</form>
<form action="" method="">
<select name="College">
<option value="Select College">Select College</option>
</select>
<input type="submit" />
</form>
</body>
</html>
Here is my php code:
Code: Select all
Welcome <?php echo $_POST["State"]; ?>!<br />
<!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>Untitled Document</title>
</head>
<body>
select your state:
<form action="Drop.php" method="post">
<select name="State">
<option value="NY">NY</option>
<option value="ND">ND</option>
</select>
<input type="submit" />
</form>
<?php if (isset($_POST['State'])){
$state = $_POST['State'];
echo "Country Selected: ". $state . "<br />";
}?>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("books", $con);
$result = mysql_query("SELECT * FROM schools WHERE State='$state'");
echo "<form >
<select action=''>";
while($row = mysql_fetch_array($result))
{
echo "<option value='$row['School']'>" . $row['School'] . "</option";
}
echo " </select>";
echo " </form>";
?>
</body>
</html>