Well, I'm taking this one step at a time. I'm trying the static route first, but the script suggested above created a two-letter state code all mixed up with control characters, so the query didn't work properly (e.g.: http://localhost/~jim/storesnearyou.php?stateName=%5C%22CA%5C%22 [instead of .php?stateName=CA]).
Did the responder mean to say "variable variable"? I haven't been able to find any reference to that.
Did the responder mean to type "$$stateName"?
Here's my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Untitled</title>
<meta name="generator" content="BBEdit 6.5">
</head>
<body>
<h3>Stores Near You</h3>
<form action="http://localhost/~jim/storesnearyou.php" method="get" name="FormName">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right">Select a State:</td>
<td>
<php?
if (isset ($stateName)) {
$$statename = 'selected';
}
echo '<select name="stateName" size="1">';
echo '<option>-------</option>';
echo "<option value=\"CA\" $CA>California</option>";
echo "<option value=\"CO\" $CO>Colorado</option>";
</select>
</td>
</tr>
<tr>
<td align="right">Then click:</td>
<td><input type="submit" value="Submit" border="0"></td>
</tr>
</table>
</form>
<p></p>
<?php
// Connect to the database server
$dbcnx = @mysql_connect("localhost",
"root", "password");
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
// Select the Stores database
if (! @mysql_select_db("Stores2") ) {
echo( "<P>Unable to locate the store " .
"database at this time.</P>" );
exit();
}
?>
<P>Here are all the stores selling our products in the state you selected.</P>
<BLOCKQUOTE>
<?php
// Request the store names of all the stores
$result = mysql_query(
"SELECT StoreName1, StoreName2 , StoreAddress , StoreCity ,
StoreState , StoreZip , StorePhone
FROM tblStores WHERE StoreState = '$stateName'
ORDER BY tblStores.StoreZip");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
// Display the name of each store in a paragraph
while ( $row = mysql_fetch_array($result) ) {
if ( ( $row["StoreName2"] == "")) {
echo("<P>" . stripslashes($row["StoreName1"]) . "<br>");
} else {
echo("<P>" . stripslashes($row["StoreName2"]) . "<br>");
}
echo( $row["StoreAddress"] . "<br>");
echo( $row["StoreCity"] . ", ");
echo( $row["StoreState"] . " ");
$zip = $row["StoreZip"];
echo( substr($zip, 0, 5) . "<br>");
echo( $row["StorePhone"] . "</P>");
}
?>
</body>
</html>