Here is a simple outline that I use to build a web interface to a MySQL database using PHP.
1) create the database
2) create a HTML form to capture data elements with *.php extension, <FORM ACTION="add_xx.php" METHOD="post"> to pass VALUEs for processing, form field NAME= should be same as database field names
3) add_xx.php = process VALUEs from form input, check for empty required fields, make connection to MySQL database using web2_connect() function found in xx_db2.inc an include file with user permissions to add to database.
//be sure to addslashes() to data
$field1 = addslashes($field1);
$field2 = addslashes($field2);
//include connection code
//call connection function
or exit ();
Include file is outside the web directory structure.
# functions to connect to database
# connect with webuser2 who has select, insert, delete, update privileges
function web2_connect ()
$db = @mysql_pconnect("localhost", "your_user_here", "your_password_here");
if ($db && mysql_select_db("your_database_here"))
echo "<P>Error: Could not login to server. Please try again later.<P>";
After connecting then INSERT data:
//data inserted needs to be in the same order that the fields are in the database - use describe to get field order
$query = "insert into your_database_here values
('".$field1."', '".$field2."', '".$field3."', '".$field4."')";
$result = mysql_query($query);
//test result and report success
echo "Success: ".mysql_affected_rows()." entry inserted into database.";
//end of add_xx.php
4) create user interface to view all entires in Table format with link to Edit or Delete entry: display_xx.php
5) create HTML form to Edit entry: edit_xx.php
6) create PHP to Update record after Edits: upd_xx.php
Seems like alot but once you have a working structure it is very easy to duplicate for another application.
If you want a complete template let me know and I'll put one together for you and post it here.