Ok I have been going through the tutorials and this is what I have come up with. I have has many syntax errors and plain old errors that I have worked through. I have put the code for one of my add pages here to get some feed back. It works with inputting 1 field only at this time. I have not had success getting multiple fields. I was hoping to get the page to print "Student add success!!!!!!!!!!!!" when the add is success. It prints out error but the add was completed.
I would like some feed back so I know if I am on the right track. This is a basic page I am have not got into error checking, or string checking. Right now I want a table with input fields and a button to add a person to the database. When I get that working and understand it I plan on adding more to it.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DaDz Add Skydiver</title>
</head>
<body>
<h1>Far North Skydive Center in Alaska</h1>
<h3>Add Student</h3>
<?php
if ( isset( $lName ) ) {
// check user input here!
$dberror = "";
$ret = add_to_database( $lName );
if ( ! $ret )
print "Error: $dberror<BR>";
else
print "Student add success!!!!!!!!!!!!";
}
else {
Write_form();
}
// Function add Last Name to Database
function add_to_database($lName, $fname){
// database connection info
$conn = mysql_connect("localhost", "dbuser", "dbpass") or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('dbname',$conn) or trigger_error("SQL", E_USER_ERROR);
if($_POST['lName']) {
// little bit of cleaning...
$lname = mysql_real_escape_string($_POST['lName']);
// insert new name into table
$sql = "INSERT INTO skydiver (skynum, lName) VALUES ('','$lName')";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
} // end if
}// End Function
function Write_form()
{
echo <<<TABLE
<form action = '{$_SERVER['PHP_SELF']}' method = 'post'>
<table border = '0'>
<tr>
<td>First Name</td>
<td><input type="text" name="fName"></td>
<td><input type="checkbox" name="chkId">Check ID</td
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lName"></td>
<td><input type="checkbox" name="chkWaiverVideo">Waiver Video Complete</td>
</tr>
<tr>
<td></td>
<td align = 'center'><input type = 'submit' value = 'ADD'></td>
<td></td>
</tr>
</table>
</form>
TABLE;
}// end Write_form function
?>
</body>
</html>