yandoo Posted January 25, 2008 Share Posted January 25, 2008 Hi there, Is it possible to have mutliple form variables in a form on one page thats will POST the details of the record (Primary ID key) to another page but also post another attribute from page one also??? I have 2 pages "stage 1 & stage 2" Stage 1 is simple form to input details of an animal - the record inserted and takes user to stage 2 Stage 2 is a complete replication of the stage 1 with a few additonal details that the user can add. In stage 2 a query displays the last updated record in the database (which is what the user has just inserted) One of the additional details in stage 2 is the Breed of the animal. This is presented in a list menu of all the breeds avaliable.... This is where my problem is!! Inorder for me display only the relevant animal breeds in the list menu, i must select ONLY the animal breed that is of the AnimalType that has been inserted in the previous page and displayed here. So somehow i need a query that will compare the AnimalType From both breed table and (last updated)Animal table??? On stage 1 i added a php POST of the AnimalTypeID.......I then created a query on stage 2 that Selected only records from Breed table WHERE AnimalTypeID(of breed table) = AnimalTypeID (of animal table) It doesnt work??? It doesnt display any breeds at all???????? Heres what my tables look like: Table "Animal" AnimalID - (primary) AnimalTypeID -(index) BreedID -(index) AnimalName Age Sex Table "AnimalType" AnimalTypeID - (primary) AnimalTypeName Table "Breed" BreedID - (primary) AnimalTypeID -(index) BreedName Heres what my 2 pages (Stage 1 and Stage 2) look like: Stage 1 <?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`, `Time`, 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, %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($_POST['hiddenField'], "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><p> <input type="text" name="Date" value="<?php echo date('Y-m-d'); ?>" size="32"> </p> </td> </tr> <tr valign="baseline"> <td nowrap align="right">Time</td> <td><input type="hidden" name="hiddenField2" value="<?php $now = getdate(time('G')); echo $now['hours'] . ":" . $now['minutes'] . ":" . $now['seconds']; ?> <?php $now = getdate(time('G')); $hours = $now['hours']; $minutes = str_pad($now['minutes'], 2, "0", STR_PAD_LEFT); $seconds = str_pad($now['seconds'], 2, "0", STR_PAD_LEFT); echo $hours.":". $minutes.":".$seconds; ?>" /></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"> <?php $_GET['AnimalTypeID']; ?></form> <p> </p> </body> </html> <?php mysql_free_result($Recordset1); ?> and stage 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['checkbox']) ? "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 = "stage2.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } mysql_select_db($database_woodside, $woodside); $query_animal = "SELECT * FROM animal ORDER BY AnimalID DESC"; $animal = mysql_query($query_animal, $woodside) or die(mysql_error()); $row_animal = mysql_fetch_assoc($animal); $totalRows_animal = mysql_num_rows($animal); $colname_Recordset1 = "-1"; if (isset($_POST['AnimalTypeID'])) { $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['AnimalTypeID'] : addslashes($_POST['AnimalTypeID']); } mysql_select_db($database_woodside, $woodside); $query_Recordset1 = sprintf("SELECT BreedID FROM breed WHERE AnimalTypeID = '%s'", $colname_Recordset1); $Recordset1 = mysql_query($query_Recordset1, $woodside) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); $breedtype = "SELECT BreedID, Breed.AnimalTypeID FROM Breed INNER JOIN AnimalType ON AnimalType.AnimalTypeID = Breed.AnimalTypeID"; $result = mysql_query($breedtype) or die(mysql_error()); ?> <!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"> <?php do { ?> <option value="<?php echo $row_Recordset1['BreedID']?>"><?php echo $row_Recordset1['BreedID']?></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> <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"> <label> <input <?php if (!(strcmp($row_animal['ExpOffLead'],1))) {echo "checked=\"checked\"";} ?> type="checkbox" name="checkbox" value="checkbox" /> </label></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> <?php echo $breedtype;?> <input type="hidden" name="MM_update" value="form1"> <input type="hidden" name="AnimalID" value="<?php echo $row_animal['AnimalID']; ?>"> </form> <?php echo $row_animal['AnimalTypeID']?> <p> </p> </body> </html> <?php mysql_free_result($animal); mysql_free_result($Recordset1); ?> If anybody can help me please do id be most greatful as im really stuck now.. Thanks for listneing Tom Link to comment https://forums.phpfreaks.com/topic/87757-multple-form-variables/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.