ok. I figured it out. There were a few things wrong but I was mostly right about the isset() (kinda). Actually...this had more to do with you just not knowing how the server was parsing through your CGI variables. The php.ini file the register_globals is probably off. To work around that, you have to be a little more articulate about your HTTP*VARS. Here is what I fixed.
- To get around the above mentioned HTTP_POST_VARS thing, you need to declare your CGI variables as parts of the HTTP_POST_VARS array. Your isset() showing that $submit was not set. This is because $submit wasn't a real variable. However, $HTTP_POST_VARS[submit] WAS a real variable and therefore works.
-- snip --
if (isset($HTTP_POST_VARS[submit])) {
$doit = 1;
$i = 0;
if ($HTTP_POST_VARS[lastName] == "") {
$error[$i] = "Lastname is required!";
$lastnamebox = "badbox";
$doit = 0;
$i++;
}
Subsequently, everything else needed to updated to.
- Your if-then statement had its curly braces effectively placed in the wrong place.
-- old clip --
if (isset($HTTP_POST_VARS[submit]))
$doit = 1;
$i = 0;
} <--- WRONG
if ($HTTP_POST_VARS[lastName] == "") {
$error[$i] = "Lastname is required!";
$lastnamebox = "badbox";
$doit = 0;
$i++;
}
+++++_
if (isset($HTTP_POST_VARS[submit])) { <-- RIGHT
$doit = 1;
$i = 0;
if ($HTTP_POST_VARS[lastName] == "") {
$error[$i] = "Lastname is required!";
$lastnamebox = "badbox";
$doit = 0;
$i++;
}
+++++_
The code works beautifully now. I will paste the whole thing in here if I can as my cable modem is not connecting right now 🙁 If you want to use what I put in here, you will have to uncomment a few things and change the form tags back to your old names (sorry). Oh and I have a few debugging messages (now commented out as well) that you may want to remove. This is really nice code though. Hope you don't mind if I use it. 🙂
<?
// Copyright 2000 - Hans Buis
// hans@framers.nl
// http://www.framers.nl
// Framers VOF
//
// Made for Network Appliance
//
// In this file there are, too make it simple three steps:
//
//
// require "connect.php";
//require "functions.php";
//require "class.Validator.php";
$firstnamebox = "textbox";
$lastnamebox = "textbox";
$mobilephonebox = "textbox";
$normalphonebox = "textbox";
$extphonebox = "textbox";
$departmentbox = "textbox";
$jobdescriptionbox = "textbox";
//if (isset($HTTP_POST_VARS[submit])) { echo "submit is set to $HTTP_POST_VARS[submit]<br>\n"; } else { echo "submit is not set!<br>\n";}
/ if ($HTTP_POST_VARS) {
while (list($key, $val) = each($HTTP_POST_VARS)) {
$tablefields = "$key";
$tablevalues = "$val";
echo "$tablefields -> $tablevalues<br>\n";
}
}
/
if (isset($HTTP_POST_VARS[submit])) {
$doit = 1;
$i = 0;
if ($HTTP_POST_VARS[lastName] == "") {
$error[$i] = "Lastname is required!";
$lastnamebox = "badbox";
$doit = 0;
$i++;
}
if ($HTTP_POST_VARS[firstName] == "") {
$error[$i] = "Firstname is required";
$firstnamebox = "badbox";
$doit = 0;
$i++;
}
if ($HTTP_POST_VARS[normalPhone] == "") {
$error[$i] = "Phone is required";
$normalphonebox = "badbox";
$doit = 0;
$i++;
}
if ($HTTP_POST_VARS[extPhone] == "") {
$error[$i] = "A 5 digit extension is required";
$extphonebox = "badbox"; $doit = 0; $i++;
}
if ($HTTP_POST_VARS[mobilePhone] == "") {
$error[$i] = "Mobile phone is mandatory, if not available, enter n/a";
$mobilephonebox = "badbox";
$doit = 0;
$i++;
}
if ($HTTP_POST_VARS[jobDescription] == "") {
$error[$i] = "Jobdescription required";
$jobdescriptionbox = "badbox";
$doit = 0;
$i++;
}
if ($HTTP_POST_VARS[department] == "") {
$error[$i] = "A 5 digit department number is required";
$departmentbox = "badbox";
$doit = 0;
$i++;
}
}//End if submit
if ($submit && ($doit == 1)) { // Finally ... pff.. we can submit it to the database
$gokomma = 0;
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
if ($gokomma > 0) {
$tablefields = "$tablefields, $key";
$tablevalues = "$tablevalues, $val";
} else {
$tablefields = "$key";
$tablevalues = "$val";
$gokomma++;
}
} // end while
// $sql = "INSERT INTO $table ($tablefields) VALUES ($tablevalues)";
// echo $sql;
// $dbupdated = 1;
//
}
?>
<head>
<title>Submit a new employee</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.textbox { background: transparent; background-color: White; border: 2px solid #CCCCFF; color: #000000; font-family: Verdana,Arial,Helvetica; font-size: x-small; text-align: left; scrollbar-face-color: #CCCCCC; scrollbar-shadow-color: #FFFFFF; scrollbar-highlight-color: #FFFFFF; scrollbar-3dlight-color: #FFFFFF; scrollbar-darkshadow-color: #FFFFFF; scrollbar-track-color: #FFFFFF; scrollbar-arrow-color: #000000 }
.badbox { background: transparent; background-color: White; border: 2px solid #FF0033; color: #000000; font-family: Verdana,Arial,Helvetica; font-size: x-small; text-align: left; scrollbar-face-color: #CCCCCC; scrollbar-shadow-color: #FFFFFF; scrollbar-highlight-color: #FFFFFF; scrollbar-3dlight-color: #FFFFFF; scrollbar-darkshadow-color: #FFFFFF; scrollbar-track-color: #FFFFFF; scrollbar-arrow-color: #000000 }
TD {font-size: 10pt; font-family: Verdana,Arial,Helvetica}
BODY {font-size: 10pt; font-family: Verdana,Arial,Helvetica}
-->
</style>
</head>
<body bgcolor="#FFFFFF">
<p align=left><a href="showsource.php?file=office.php">View Source</a></p>
<p align="center"><img src="images/logo.jpg" width="300" height="100"></p>
<p align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Submit
a new employee</b><br>
<br>
This form works with form validation, you won't be able to submit<br>
</font><font face="Verdana, Arial, Helvetica, sans-serif" size="2">a new employee
without entering the right values.</font><br><br>
<? // stond form=
?>
<? if ($submit && ($doit == 0)) { ?>
<table align="center">
<tr>
<td colspan=2>Sorry there were the following problems with your submission:<ul>
<?
for ($j=0;$j < count($error);$j++) {
print "<li><b>". $error[$j] ."</b>\n";
}
?>
</ul>
</td>
</tr>
</table>
<? } ?>
<form name="office" method="post" action="office.php">
<table width="60%" border="0" bgcolor="#000066" cellspacing="2" align="center">
<? if (($submit && ($doit == 0)) || !$submit) { ?>
<tr bgcolor="#FFFFFF">
<td width="15%" bgcolor="#CCCCFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Lastname:</font></b></td>
<td width="37%">
<input class=<? echo $lastnamebox ?> type="text" name="lastName" value="<? echo $HTTP_POST_VARS[lastName] ?>">
</td>
<td width="13%" bgcolor="#CCCCFF"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Firstname:
</font></b></td>
<td width="35%">
<input class=<? echo $firstnamebox ?> type="text" name="firstName" value="<? echo $HTTP_POST_VARS[firstName] ?>">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="15%"><b></b></td>
<td width="37%"> </td>
<td width="13%"><b></b></td>
<td width="35%"> </td>
</tr>
<tr bgcolor="#000066">
<td width="15%" height="12" bgcolor="#CCCCFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Phone:</font></b></td>
<td height="12" bgcolor="#FFFFFF" width="37%">
<input class=<? echo $normalphonebox ?> type="text" name="normalPhone" value="<? echo $HTTP_POST_VARS[normalPhone] ?>">
</td>
<td height="12" bgcolor="#CCCCFF" width="13%"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Extension:
</font></b></td>
<td height="12" bgcolor="#FFFFFF" width="35%">
<input class=<? echo $extphonebox ?> type="text" name="extPhone" value="<? echo $HTTP_POST_VARS[extPhone] ?>">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="15%" bgcolor="#CCCCFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Mobile:</font></b></td>
<td width="37%">
<input class=<? echo $mobilephonebox ?> type="text" name="mobilePhone" value="<? echo $HTTP_POST_VARS[mobilePhone] ?>">
</td>
<td height="12" bgcolor="#FFFFFF" width="13%"> </td>
<td height="12" bgcolor="#FFFFFF" width="35%"> </td>
</tr>
<tr bgcolor="#000066">
<td width="15%" bgcolor="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></b></td>
<td bgcolor="#FFFFFF" width="37%"> </td>
<td height="12" bgcolor="#FFFFFF" width="13%"> </td>
<td height="12" bgcolor="#FFFFFF" width="35%"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="15%" bgcolor="#CCCCFF" height="2"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Job
Description:</font></b></td>
<td width="37%" height="2">
<input class=<? echo $jobdescriptionbox ?> type="text" name="jobDescription" value="<? echo $HTTP_POST_VARS[jobDescription] ?>">
</td>
<td height="12" bgcolor="#FFFFFF" width="13%"> </td>
<td height="12" bgcolor="#FFFFFF" width="35%"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="15%" bgcolor="#CCCCFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Department:</font></b></td>
<td width="37%">
<input class=<? echo $departmentbox ?> type="text" name="department" value="<? echo $HTTP_POST_VARS[department] ?>">
</td>
<td height="12" bgcolor="#FFFFFF" width="13%"> </td>
<td height="12" bgcolor="#FFFFFF" width="35%"> </td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="15%"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></b></td>
<td colspan="3">
<input type="submit" name="submit" value="Validate">
<input type="hidden" name="table" value="phonelist">
</td>
</tr>
</table>
<? } ?>
<?
if ($dbupdated == 1) {
?>
<table>
<tr><td colspan=2>Thank you for adding your listing. <br></td></tr>
</table>
<?
echo "<center><br><br>";
echo "Well done, we'll submit some stuff to the database<br><br>\n";
echo "<table><tr><td><b>Field Value:</b></td><td><b>Field Inserted Value:</b></td></tr>\n";
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
echo "<tr><td>$key:</td><td>$val</td></tr>\n"; }
echo "</table></center>\n";
}
?>
</form>