Thanks for your feedback, I made some changes to my original script and responded to tomhath's post. I am still getting an error. Here it is:
Warning: Undefined variable: submit in D:\Inetpub\wwwroot\user\add.php on line 9
$submit is the variable for my submit button.
Here's my script after changes:
<head>
<title>Workorder submission form</title>
</head>
<body>
<?
//haven't submitted form, so display it
if (!$submit)
{
?>
<table cellspacing="5" cellpadding="5">
<form action="<?echo $PHP_SELF; ?>" method="post">
<tr>
<td>Name:</td>
<td><input size="50" maxlength="250" type="text" name="name"></td>
</tr>
<tr>
<td>Extension:</td>
<td><input size="4" maxlength="4" type="text" name="ext"></td>
</tr>
<tr>
<td>Email:</td>
<td><input size="50" maxlength="250" type="text" name="email"></td>
</tr>
<tr>
<td>Issue/Error/Problem:</td>
</tr>
<tr>
<td><textarea name="issue" cols="40" rows="20"></textarea></td>
</tr>
<tr>
<td><input type="Submit" name="submit" value="Add"></td>
</tr>
</form>
</table>
<?
}
else
{
//includes files
include("../conf.php");
include("../functions.php");
//setup up an error list array
$errorList = array();
$count = 0;
//validate name field
if (!$name) { $errorList[$count] = "Invalid entry: Name"; $count++; }
//validate ext field
if (!$ext) { $errorList[$count] = "Invalid entry: Extension"; $count++; }
//validate email field
if (!$email) { $errorList[$count] = "Invalid entry: Email"; $count++; }
//validate issue field
if (!$issue) { $errorList[$count] = "Invalid entry: Issue/Error/Problem"; $count++; }
//check for errors in errorlist.
if (sizeof($errorList)==0)
{
//if no errors found
//open db connection
$connection = mysql_connect($host, $user, $pass) or die("Unable to Connect!");
//select db
mysql_select_db($db) or die("Unable to select database!");
//generate and run query
$query = "INSERT INTO wo(name, ext, email, issue, timestamp) VALUES ('$name', '$ext', '$email', '$issue', now())";
$result = mysql_query($query) or die("Error in query: $query. " . mysql_error());
//echo result
echo "<font size=-1>Update Successful.<a href=list.php>Go back to the main menu</a>.</font>";
//close db
mysql_close($connection);
}
else
{
//if there are errors, print a list
echo "<font size=-1>The following errors were encountered:<br>";
echo "<ul>";
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo "</ul></font>";
}
}
?>
</body>
Thanks in advance for all of your help!