Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form editing prior to submit

Status
Not open for further replies.

akaballa123

Technical User
Apr 29, 2008
46
US
Hi,

I have a form that directs to a form summary page after being submitted. the summary page inserts the data into the db and also displays the form values. i want add a edit option where the user can edit their form is they entered a wrong value. Basically the user will have two options, 'edit', 'submit' on the summary page. If the edit button is clicked the user will be directed to the form with all of the $POST contents. If the user clicks submit, then the data will be entered into the db. How can I implement this logic into my code:

This is what i have currently for my summary page:

Code:
<?php
/*session_start();
if($_SESSION['UID'] = 1)
{
   session_unset();
   session_destroy();
}  */
//continue and end session from form.  Duplication prevention
?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<link type="text/css" rel="stylesheet" href="webLayout.css">
<meta name="generator">
<title>Form Summary</title>
<div class="cecbanner">
<img src="cecBanner1.gif" width="600" height="60" border="0" alt="AS Trainings Tool">
</div>
</head>
<body>
<div id="stylized" class="myform">
<form>

<?php


//header( 'Location:' ) ;

include("mysqlConnection.php");

$result = @mysql_query('SELECT * FROM courses');
$trainings=@mysql_query('SELECT * FROM trainings');

$errmsg  = ''; // error message

   $empname  = $_REQUEST['empName'];
   $eID   = $_REQUEST['empID'];
   $sdate = $_REQUEST['startDate'];
   $edate = $_REQUEST['endDate'];
   $tDuration = $_REQUEST['trainingDuration'];
   $cid = '';
   $splitData = explode ( '>>' , $_REQUEST['training'] );
   while($course = mysql_fetch_array($result))
    {

         if($splitData[0] == $course['courseName'] && $splitData[1] == $course['courseInstructor'])
         {
            $cid = $course['courseID'];
            break;
         }
    }

   if(trim($empname) == '')
   {
      $errmsg = 'Please enter your name';

      echo $errmsg;
   }
   else if(trim($eID) == '')
   {
      $errmsg = 'Please enter your Employee Badge Number';
      echo $errmsg;
   }
   else if(trim($sdate) == '')
   {
      $errmsg = 'Please enter a start date';
      echo $errmsg;
   }
   else if(trim($edate) == '')
   {
      $errmsg = 'Please enter an end date';
      echo $errmsg;
   }
   else if(trim($tDuration) == '')
   {
      $errmsg = 'Please enter the Training Duration';
   }
   
   
   if($errmsg == '')
   {
     //this is where i summarize and submit the form values to db server
      echo '<br><br> <b>Employee Name: </b>  '. $_REQUEST['empName'] . '<br><br>';

      echo '<b>Employee ID: </b>  '. $_REQUEST['empID'].'<br><br>';

      echo '<b>Course Name: </b>  '. $splitData[0].'<br><br>';
      
      echo '<b>Course Instructor :</b>  '. $splitData[1].'<br><br>';

      echo '<b>Start Date :</b>  '. $_REQUEST['startDate'].'<br><br>';

      echo '<b>End Date :</b>  '. $_REQUEST['endDate'].'<br><br>';
      
      echo '<b>Training Duration (# of Hours): </b>  '. $_REQUEST['trainingDuration'].'<br><br>';

      echo '<b>Location :</b>  '. $_REQUEST['location'].'<br><br>';

      echo '<br><br><p>&nbsp;<a href="selectionmenu.php">Go Back to Main Menu</a></p>';
      
      $insert = "INSERT INTO trainings
      (employeeName, employeeID, courseID, startDate, endDate, trainingDuration, courseInstructor, location)
      VALUES('$_REQUEST[empName]','$_REQUEST[empID]',
      '$cid' , '$_REQUEST[startDate]', '$_REQUEST[endDate]' , ' $_REQUEST[trainingDuration]' , '$splitData[1]' , '$_REQUEST[location]')";


      if (!mysql_query($insert))
      {
        die('Error: ' . mysql_error());
      }
      else
      {
        echo "Thank you for submitting!";
      }


   }


include("mysqlConnClose.php")
?>

</form>
</div>
</body>
</html>
 
You'll need to store the form information somewhere, usually in a Session, so you can then use it again in your form page to re-display the entered information.

You'll need to add a button or link for the edit option that when clicked triggers the relevant actions.







----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top