<?
/*
Please realize that although this may seem to work as intended there are a few issues to consider:
- Create valid HTML: Include encoding and HTML version in your header
- Check userdata for their input. I can prechew, but it is better for you to have a read on sql injection
- A user which reloads a page can insert many instancesa of the same data. You might want to put a check in to prevent this, e.g., store a session variable when the page is loaded, and modifying it when the data has been processed. Then only data from the newly loaded form van be inserted. In short: Have a think about the different scenarios possible before putting such code online.
*/
?>
<html><head></head><body>
<?php
// first, lets see whether data has to be inserted:
if(isset($_POST['submit']))
{
// I presume you have a posted variable called store?
$store = $_POST['store'];
// Open a database connection. You already select the database, so no need to double the select
$link = mysql_connect ("mysql-server.net", "username", "password")
or die(mysql_error());
// debugging help
echo $_POST['store'];
// create query
$sql = "insert into store (store) values ('$store')";
// insert record
$result = mysql_query($sql) or die(mysql_error());
// close connection
mysql_close($link);
}
// no need for else, as you want to show the form again!
?>
<table width="800" border="0" cellpadding="0" cellspacing="0" summary="">
<tr>
<td align="center"><br><br><form method="post" action="store_form.php">
<b>Store Name: </b><input type="text" name="store"> <br>
<input type="submit" name="submit" value="insert"></form>
</td>
</tr>
</table>
</body>
</html>