I finally got my form to work, inasmuch as it takes the information and inserts it into my database table.
I still need to learn a few more things, but taking the two most simple ones, I need to
1. display back to the person what they entered (I presume this would be on a new page) and
2. clear the form (at least, on my own same system the form apparently continues to hold the last entered data
I'm wondering if this has to do with changing the form's beginning <?php echo($_SERVER['PHP_SELF']); ?> or not... ? (among other things)
I know I need to learn how to validate and other things, but I won't go into that in this topic.
Current code is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<?php
$street = $_POST["street"];
$city = $_POST["city"];
$stateabbr = $_POST["stateabbr"];
$zipcode = $_POST["zipcode"]; ?>
<?php
$connection = mysql_connect("localhost", "user", "password");
if (!$connection){
die("Could not connect to the database: <br/>" . mysql_error());
}
$db_select = mysql_select_db("database name");
if (!$db_select) {
die ("could not select the database: <br />". mysql_error());
}
?>
<?php
$query = mysql_query ("INSERT INTO location (street, city, stateabbr, zipcode) VALUES
('$street','$city','$stateabbr','$zipcode')");
if (!empty($street)&& !empty($city) && !empty($stateabbr) && !empty($zipcode)){
$query;
}
?>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>"
method="post">
<label>
Street: <input type="text" name="street" value="<?php echo $street; ?>"/>
</label>
<label>
City: <input type="text" name="city" value="<?php echo $city; ?>" />
</label>
<label>
State Abbrev: <input type="text" name="stateabbr" value="<?php echo $stateabbr; ?> "/>
</label>
<label>
Zip Code: <input type="text" name="zipcode" value="<?php echo $zipcode; ?>" />
</label>
<input type="submit" value="Submit" />
</form>
</body>
</html>