bCourtney07 Posted December 7, 2007 Share Posted December 7, 2007 First of all, heres my code <html> <title>Human Resources Employee Wellness Program</title> <body> <?php require("config.php"); //Checks to make sure no fields are blank $empties = array(); foreach($_POST as $key=>$value){ if(empty($value)){ $empties[] = $key; } } if(count($empties) > 0){ echo "Please fill in all required fields before submitting.<br/>"; echo "The following fields were emtpy:<br/>"; echo "<ul>"; foreach($empties as $empty){ echo "<li>".$empty."</li>"; } echo "</ul>"; exit; } // Query string to select employee name to display if they enter the correct employee_id $query="SELECT First_Name, Last_Name FROM Employee_Classification_Department WHERE Employee_ID = '{$_POST["Employee_ID"]}'"; //executes query $rs = $conn->execute($query); $num_columns = $rs->Fields->Count(); for ($i=0; $i < $num_columns; $i++) { $fld[$i] = $rs->Fields($i); } echo "<table align=center>"; while (!$rs->EOF) { echo "<tr><br></tr>"; echo "<tr>"; echo "<td>Thank you</td>"; for ($i=0; $i < $num_columns; $i++) { echo "<td>" . $fld[$i]->value . "</td>"; } echo "<td>for participating in the Human Resources Employee Wellness Program.</td>"; echo "</tr>"; echo "<tr><br></tr>"; echo "<tr><br></tr>"; echo "<tr>"; echo "<td colspan=8 align=center><a href=http://merlin/WellnessProgram/WellnessForm.htm>Return to Wellness Form</a></td>"; echo "</tr>"; $conn->execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')"); $rs->MoveNext(); //move on to the next record } echo "</table>"; $rs->Close(); $conn->Close(); $rs = null; $conn = null; echo "<table align=center> <tr> <td>Not seeing your name? Make sure you have the correct Employee ID before you submit the form!</td> </tr> </table>"; ?> </body> </html> Would it be possible to add something to that code to check to see if the user enters either miles or minutes into a text box? and not both? ??? or will i have to rewrite the code another way? I have to add another field to the form so users can enter Minutes instead of miles, but some users do miles instead of minutes...I appologize if i confuse you. Quote Link to comment Share on other sites More sharing options...
kairno Posted December 7, 2007 Share Posted December 7, 2007 Well... all you can do as far as i see it is to check if the value is over 60 ... but then again 60 miles is a long way... you could do a page that writes the info they passed so they can validate it... otherwise i don't know any way of checking... Quote Link to comment Share on other sites More sharing options...
bCourtney07 Posted December 7, 2007 Author Share Posted December 7, 2007 Well... all you can do as far as i see it is to check if the value is over 60 ... but then again 60 miles is a long way... you could do a page that writes the info they passed so they can validate it... otherwise i don't know any way of checking... I just want it so...say somebody enters minutes, and the miles text box is empty, i don't want it to echo out as being empty. Or say somebody enters miles, and the minutes is empty.... ok for some reason my code is showing funky to me so here it is again <html> <title>Human Resources Employee Wellness Program</title> <body> <?php require("config.php"); //Checks to make sure no fields are blank $empties = array(); foreach($_POST as $key=>$value){ if(empty($value)){ $empties[] = $key; } } if(count($empties) > 0){ echo "Please fill in all required fields before submitting.<br/>"; echo "The following fields were emtpy:<br/>"; echo "<ul>"; foreach($empties as $empty){ echo "<li>".$empty."</li>"; } echo "</ul>"; exit; } // Query string to select employee name to display if they enter the correct employee_id $query="SELECT First_Name, Last_Name FROM Employee_Classification_Department WHERE Employee_ID = '{$_POST["Employee_ID"]}'"; //executes query $rs = $conn->execute($query); $num_columns = $rs->Fields->Count(); for ($i=0; $i < $num_columns; $i++) { $fld[$i] = $rs->Fields($i); } echo "<table align=center>"; while (!$rs->EOF) { echo "<tr><br></tr>"; echo "<tr>"; echo "<td>Thank you</td>"; for ($i=0; $i < $num_columns; $i++) { echo "<td>" . $fld[$i]->value . "</td>"; } echo "<td>for participating in the Human Resources Employee Wellness Program.</td>"; echo "</tr>"; echo "<tr><br></tr>"; echo "<tr><br></tr>"; echo "<tr>"; echo "<td colspan=8 align=center><a href=http://merlin/WellnessProgram/WellnessForm.htm>Return to Wellness Form</a></td>"; echo "</tr>"; $conn->execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')"); $rs->MoveNext(); //move on to the next record } echo "</table>"; $rs->Close(); $conn->Close(); $rs = null; $conn = null; echo "<table align=center> <tr> <td>Not seeing your name? Make sure you have the correct Employee ID before you submit the form!</td> </tr> </table>"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
kairno Posted December 7, 2007 Share Posted December 7, 2007 you can do a javascript check and see if there are any empty fields... then point them out before you send the page... Quote Link to comment Share on other sites More sharing options...
revraz Posted December 7, 2007 Share Posted December 7, 2007 Looking at your code, its hard to tell where they would enter miles or minutes. Is it the Activity field and something else? If you have two form fields and you don't want them both filled out, just do a IF statement and if they both have data, error out and tell them to just fill out one. If you only have one form field, the I would suggest adding one more so you can tell them apart or add a radio button. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.