Hello,
I know this will probably be a dumb mistake on my part, but I can't get the following script to run. Could someone please proofread it for me and help me out? Also, since I'm learning if you'd be so kind as to critique my work, that would also be helpful.
Here's the script:
<html>
<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>
</html>
Thanks in advance for all of your help!
I know this will probably be a dumb mistake on my part, but I can't get the following script to run. Could someone please proofread it for me and help me out? Also, since I'm learning if you'd be so kind as to critique my work, that would also be helpful.
Here's the script:
<html>
<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>
</html>
Thanks in advance for all of your help!