Jump to content

3 stage form


yandoo

Recommended Posts

Hi there was hoping for a little help please,

 

Im creating for form that requries it to be completed in three stages. At each stage more of the form is completed (form details passed to each following stage) until on the final stage it is complete.

 

Initially here i start with an insert query to insert the inital record. Once the submit button is clicked the record is inserterted and the user is sent to the stage 2 page.

 

This page presents exaclty the same information except with additional form elements to it. Iam trying to use the update command to update the record further,  however....i seem to be having this page doesnt bring up the previous stages record....it is just blank???

 

the form parameter of stage1 is set to be ID key of record is stage 2...It just doesnt bring anyrecords up at all!!????

Even though no records are displayed in stage 2 the stage 1 record has been instered into the database.....

 

 

If the form was hyperlinked and not a submit button, im sure i could get the record ID to parse to the stage 2 page...but with this submit button im really not sure.....

 

Im probably not making any sense, but please if anyone can help me...do :)

 

Stage 1 code:

 

#

 

<?php require_once('Connections/woodside.php'); ?>

<?php

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

 

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO animal (AnimalID, AnimalTypeID, Name, Age, Sex, `Date`, HouseTrained, ExpCat, ExpDog, ExpCar, ExpChild, ExpAlone, ExpOnlead, ExpOffLead, Valid) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

                      GetSQLValueString($_POST['AnimalID'], "text"),

                      GetSQLValueString($_POST['select'], "text"),

                      GetSQLValueString($_POST['Name'], "text"),

                      GetSQLValueString($_POST['select3'], "int"),

                      GetSQLValueString($_POST['select4'], "text"),

                      GetSQLValueString($_POST['Date'], "date"),

                      GetSQLValueString(isset($_POST['checkbox']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['checkbox2']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['checkbox3']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['checkbox4']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['checkbox5']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['checkbox6']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['checkbox7']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['checkbox8']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString($_POST['hiddenField'], "int"));

 

  mysql_select_db($database_woodside, $woodside);

  $Result1 = mysql_query($insertSQL, $woodside) or die(mysql_error());

 

  $insertGoTo = "stage2.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

 

mysql_select_db($database_woodside, $woodside);

$query_Recordset1 = "SELECT AnimalTypeID FROM animaltype";

$Recordset1 = mysql_query($query_Recordset1, $woodside) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">

  <table align="center">

    <tr valign="baseline">

      <td nowrap align="right">AnimalID:</td>

      <td><input type="text" name="AnimalID" value="" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">AnimalTypeID:</td>

      <td><label>

        <select name="select">

          <?php

do { 

?>

          <option value="<?php echo $row_Recordset1['AnimalTypeID']?>"><?php echo $row_Recordset1['AnimalTypeID']?></option>

          <?php

} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));

  $rows = mysql_num_rows($Recordset1);

  if($rows > 0) {

      mysql_data_seek($Recordset1, 0);

  $row_Recordset1 = mysql_fetch_assoc($Recordset1);

  }

?>

        </select>

      </label></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Name:</td>

      <td><input type="text" name="Name" value="" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Age:</td>

      <td><label>

        <select name="select3">

          <option value="1">1</option>

          <option value="2">2</option>

          <option value="3">3</option>

          <option value="4">4</option>

          <option value="5">5</option>

          <option value="6">6</option>

          <option value="7">7</option>

          <option value="8">8</option>

          <option value="9">9</option>

          <option value="10">10</option>

          <option value="11">11</option>

          <option value="12">12</option>

          <option value="13">13</option>

          <option value="14">14</option>

          <option value="15">15</option>

          <option value="16">16</option>

          <option value="17">17</option>

          <option value="18">18</option>

          <option value="19">19</option>

          <option value="20">20</option>

        </select>

      </label></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Sex:</td>

      <td><label>

        <select name="select4">

          <option value="M">M</option>

          <option value="F">F</option>

        </select>

      </label></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Date:</td>

      <td><input type="text" name="Date" value="" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">HouseTrained:</td>

      <td><label>

        <input name="checkbox" type="checkbox" value="checkbox" />

      </label></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpCat:</td>

      <td><input type="checkbox" name="checkbox2" value="checkbox" /></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpDog:</td>

      <td><input type="checkbox" name="checkbox3" value="checkbox" /></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpCar:</td>

      <td><input type="checkbox" name="checkbox4" value="checkbox" /></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpChild:</td>

      <td><input type="checkbox" name="checkbox5" value="checkbox" /></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpAlone:</td>

      <td><input type="checkbox" name="checkbox6" value="checkbox" /></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpOnlead:</td>

      <td><input type="checkbox" name="checkbox7" value="checkbox" /></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpOffLead:</td>

      <td><input type="checkbox" name="checkbox8" value="checkbox" /></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Valid:</td>

      <td><input name="hiddenField" type="hidden" value="1" /></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right"> </td>

      <td><input type="submit" value="Insert record"></td>

    </tr>

  </table>

  <input type="hidden" name="MM_insert" value="form1">

</form>

<p> </p>

</body>

</html>

<?php

mysql_free_result($Recordset1);

?>

 

#

 

Stage 2 (page 2)

 

#

 

<?php require_once('Connections/woodside.php'); ?>

<?php

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

 

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

  $updateSQL = sprintf("UPDATE animal SET AnimalTypeID=%s, BreedID=%s, Name=%s, Age=%s, Sex=%s, `Date`=%s, HouseTrained=%s, ExpCat=%s, ExpDog=%s, ExpCar=%s, ExpChild=%s, ExpAlone=%s, ExpOnlead=%s, ExpOffLead=%s, Valid=%s WHERE AnimalID=%s",

                      GetSQLValueString($_POST['AnimalTypeID'], "text"),

                      GetSQLValueString($_POST['BreedID'], "text"),

                      GetSQLValueString($_POST['Name'], "text"),

                      GetSQLValueString($_POST['Age'], "int"),

                      GetSQLValueString($_POST['Sex'], "text"),

                      GetSQLValueString($_POST['Date'], "date"),

                      GetSQLValueString(isset($_POST['HouseTrained']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['ExpCat']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['ExpDog']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['ExpCar']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['ExpChild']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['ExpAlone']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['ExpOnlead']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['ExpOffLead']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString(isset($_POST['Valid']) ? "true" : "", "defined","1","0"),

                      GetSQLValueString($_POST['AnimalID'], "text"));

 

  mysql_select_db($database_woodside, $woodside);

  $Result1 = mysql_query($updateSQL, $woodside) or die(mysql_error());

 

  $updateGoTo = "stage3.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

    $updateGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $updateGoTo));

}

 

$colname_animal = "-1";

if (isset($_POST['AnimalID'])) {

  $colname_animal = (get_magic_quotes_gpc()) ? $_POST['AnimalID'] : addslashes($_POST['AnimalID']);

}

mysql_select_db($database_woodside, $woodside);

$query_animal = sprintf("SELECT * FROM animal WHERE AnimalID = '%s'", $colname_animal);

$animal = mysql_query($query_animal, $woodside) or die(mysql_error());

$row_animal = mysql_fetch_assoc($animal);

$totalRows_animal = mysql_num_rows($animal);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">

  <table align="center">

    <tr valign="baseline">

      <td nowrap align="right">AnimalID:</td>

      <td><?php echo $row_animal['AnimalID']; ?></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">AnimalTypeID:</td>

      <td><input type="text" name="AnimalTypeID" value="<?php echo $row_animal['AnimalTypeID']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">BreedID:</td>

      <td><label>

      <select name="select">

      </select>

      </label>

<input type="text" name="BreedID" value="<?php echo $row_animal['BreedID']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Name:</td>

      <td><input type="text" name="Name" value="<?php echo $row_animal['Name']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Age:</td>

      <td><input type="text" name="Age" value="<?php echo $row_animal['Age']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Sex:</td>

      <td><input type="text" name="Sex" value="<?php echo $row_animal['Sex']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Date:</td>

      <td><input type="text" name="Date" value="<?php echo $row_animal['Date']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">HouseTrained:</td>

      <td><input type="text" name="HouseTrained" value="<?php echo $row_animal['HouseTrained']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpCat:</td>

      <td><input type="text" name="ExpCat" value="<?php echo $row_animal['ExpCat']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpDog:</td>

      <td><input type="text" name="ExpDog" value="<?php echo $row_animal['ExpDog']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpCar:</td>

      <td><input type="text" name="ExpCar" value="<?php echo $row_animal['ExpCar']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpChild:</td>

      <td><input type="text" name="ExpChild" value="<?php echo $row_animal['ExpChild']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpAlone:</td>

      <td><input type="text" name="ExpAlone" value="<?php echo $row_animal['ExpAlone']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpOnlead:</td>

      <td><input type="text" name="ExpOnlead" value="<?php echo $row_animal['ExpOnlead']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">ExpOffLead:</td>

      <td><input type="text" name="ExpOffLead" value="<?php echo $row_animal['ExpOffLead']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right">Valid:</td>

      <td><input type="text" name="Valid" value="<?php echo $row_animal['Valid']; ?>" size="32"></td>

    </tr>

    <tr valign="baseline">

      <td nowrap align="right"> </td>

      <td><input type="submit" value="Update record"></td>

    </tr>

  </table>

  <input type="hidden" name="MM_update" value="form1">

  <input type="hidden" name="AnimalID" value="<?php echo $row_animal['AnimalID']; ?>">

</form>

<p> </p>

</body>

</html>

<?php

mysql_free_result($animal);

?>

 

 

#

 

 

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.