yandoo Posted February 8, 2008 Share Posted February 8, 2008 Hi there , Im currently building a form that on upate will direct to same page (using hidden, drop down, text field and form). The update works fine...But after the update has been made, the data the user just entered is displayed on screen! To do this i have built a query: SELECT *FROM animalfears WHERE AnimalID = colname I initall create it using dreamweaver which looked like: SELECT *FROM animalfears WHERE AnimalID = form variable/code] Trouble is when i test query in dream weaver it asks for the hiden variable to test the query.. and on enterring the hidden form variable in it works fine....It just doesnt work on the page..???? So I dont think its being parsed properly.... Can anybody help me please?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/90075-solved-update-record-to-same-page-using-the-form-variable-to-determine-query/ Share on other sites More sharing options...
yandoo Posted February 8, 2008 Author Share Posted February 8, 2008 Hi there, Ive made some slow progrees, i rewrote the query so that it is matche through a POST: mysql_select_db($database_woodside, $woodside); $query_animalFear2 = "SELECT * FROM animalfears WHERE AnimalID='" . $row_animalFears['AnimalID'] . "'"; $animalFear2 = mysql_query($query_animalFear2, $woodside) or die(mysql_error()); This im sure is ok, as i have it on another page i made before.... and it works!!?? The only difference is that on this form the data is displayed back to the user in a texfield with repaeat region, rather in drop down box(other working page) I dont get any results on my new page, heres the full page of 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 animalfears (AnimalFearID, AnimalID, FearID) VALUES (%s, %s, %s)", GetSQLValueString($_POST['animalFearid'], "text"), GetSQLValueString($_POST['animalid'], "int"), GetSQLValueString($_POST['fearid'], "text")); mysql_select_db($database_woodside, $woodside); $Result1 = mysql_query($insertSQL, $woodside) or die(mysql_error()); $insertGoTo = "stage3.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_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); mysql_select_db($database_woodside, $woodside); $query_animalFear = "SELECT * FROM animalfears"; $animalFear = mysql_query($query_animalFear, $woodside) or die(mysql_error()); $row_animalFear = mysql_fetch_assoc($animalFear); $totalRows_animalFear = mysql_num_rows($animalFear); mysql_select_db($database_woodside, $woodside); $query_fears = "SELECT * FROM fears"; $fears = mysql_query($query_fears, $woodside) or die(mysql_error()); $row_fears = mysql_fetch_assoc($fears); $totalRows_fears = mysql_num_rows($fears); mysql_select_db($database_woodside, $woodside); $query_animalFear2 = "SELECT * FROM animalfears WHERE AnimalID='" . $row_animalFears['AnimalID'] . "'"; $animalFear2 = mysql_query($query_animalFear2, $woodside) or die(mysql_error()); $row_animalFear2 = mysql_fetch_assoc($animalFear2); $totalRows_animalFear2 = mysql_num_rows($animalFear2); ?><!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> <link href="bordertop.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <table height ="225" border="0" align="center"> <tr valign="baseline"> <td height="20" colspan="3" align="right" valign="middle" nowrap="nowrap"> </td> </tr> <tr valign="baseline"> <td width="87" height="20" align="right" valign="middle" nowrap="nowrap"><strong>Animal ID:</strong></td> <td width="6" align="right" valign="middle" nowrap="nowrap"> </td> <td height="20" width="158" valign="middle"><?php echo $row_animal['AnimalID']; ?></td> </tr> <tr valign="baseline"> <td height="20" align="right" valign="middle" nowrap="nowrap"><strong>Animal Type:</strong></td> <td align="right" valign="middle" nowrap="nowrap"> </td> <td height="20" valign="middle"><?php echo $row_animal['AnimalTypeID']; ?></td> </tr> <tr valign="baseline"> <td height="20" align="right" valign="middle" nowrap="nowrap"><strong>Name:</strong></td> <td align="right" valign="middle" nowrap="nowrap"> </td> <td height="20" valign="middle"><label></label> <label><?php echo $row_animal['Name']; ?></label></td> </tr> <tr valign="baseline"> <td height="25" align="right" valign="middle" nowrap="nowrap"><strong>Breed:</strong></td> <td align="right" valign="middle" nowrap="nowrap"> </td> <td height="25" valign="middle"><label><?php echo $row_animal['BreedID']; ?></label></td> </tr> <tr valign="baseline"> <td height="22" align="right" valign="middle" nowrap="nowrap"><strong>Age:</strong></td> <td align="right" valign="middle" nowrap="nowrap"> </td> <td height="25" valign="middle"><label><?php echo $row_animal['Age']; ?></label></td> </tr> <tr valign="baseline"> <td height="22" align="right" valign="middle" nowrap="nowrap"><strong>Sex:</strong></td> <td align="right" valign="middle" nowrap="nowrap"> </td> <td height="25" valign="middle"><label><?php echo $row_animal['Sex']; ?></label></td> </tr> <tr valign="baseline"> <td height="22" align="right" valign="middle" nowrap="nowrap"><strong>Date:</strong></td> <td align="right" valign="middle" nowrap="nowrap"> </td> <td height="25" valign="middle"><?php echo $row_animal['Date']; ?></td> </tr> <tr valign="baseline"> <td height="25" colspan="3" align="right" valign="middle" nowrap="nowrap"> </td> </tr> </table> <p> </p> <table width="471" border="0" align="center"> <tr> <td width="461"> </td> </tr> <tr> <td> </td> </tr> </table> <table width="496" border="0" align="center"> <tr valign="baseline"> <td colspan="11" align="right" nowrap="nowrap"><div align="center"> <p><strong>Animal Experience</strong></p> <p> </p> </div></td> </tr> <tr valign="baseline"> <td width="97" height="30" align="right" valign="baseline" nowrap="nowrap">House Trained:</td> <td width="27" valign="baseline"><input <?php if (!(strcmp($row_animal['HouseTrained'],1))) {echo "checked=\"checked\"";} ?> input="input" disabled="disabled" type="checkbox" name="checkbox2" value="checkbox" /></td> <td width="7" valign="baseline"> </td> <td width="62" valign="baseline">Cats:</td> <td width="36" valign="baseline"><input <?php if (!(strcmp($row_animal['ExpCat'],1))) {echo "checked=\"checked\"";} ?> input="input" disabled="disabled" type="checkbox" name="checkbox22" value="checkbox" /></td> <td width="15" valign="baseline"> </td> <td width="39"> Cars:</td> <td width="23" valign="baseline"><input <?php if (!(strcmp($row_animal['ExpCar'],1))) {echo "checked=\"checked\"";} ?> input="input" disabled="disabled" type="checkbox" name="checkbox24" value="checkbox" /></td> <td width="9" valign="baseline"> </td> <td width="63" valign="baseline">Children:</td> <td width="72" valign="baseline"><input <?php if (!(strcmp($row_animal['ExpChild'],1))) {echo "checked=\"checked\"";} ?> input="input" disabled="disabled" type="checkbox" name="checkbox25" value="checkbox" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">On lead:</td> <td><input <?php if (!(strcmp($row_animal['ExpOnlead'],1))) {echo "checked=\"checked\"";} ?> input="input" disabled="disabled" type="checkbox" name="checkbox27" value="checkbox" /></td> <td> </td> <td> Off Lead:</td> <td><input <?php if (!(strcmp($row_animal['ExpOffLead'],1))) {echo "checked=\"checked\"";} ?> input="input" disabled="disabled" type="checkbox" name="checkbox" value="checkbox" /></td> <td> </td> <td>dogs:</td> <td><input <?php if (!(strcmp($row_animal['ExpDog'],1))) {echo "checked=\"checked\"";} ?> input="input" disabled="disabled" type="checkbox" name="checkbox23" value="checkbox" /></td> <td> </td> <td>alone:</td> <td><input <?php if (!(strcmp($row_animal['ExpAlone'],1))) {echo "checked=\"checked\"";} ?> input="input" disabled="disabled" type="checkbox" name="checkbox26" value="checkbox" /></td> </tr> <tr valign="baseline"> <td colspan="11" align="right" nowrap="nowrap"> </td> </tr> </table> <p> </p> <table width="200" border="0" align="center"> <tr> <td align="center"><input name="submit" type="submit" value="Update record" /></td> </tr> </table> <p> </p> <table height ="117" border="0" align="center"> <tr valign="baseline"> <td height="20" colspan="3" align="right" valign="middle" nowrap="nowrap"> </td> </tr> <tr valign="baseline"> <td width="87" height="20" align="right" valign="middle" nowrap="nowrap">Fear Name: </td> <td width="6" align="right" valign="middle" nowrap="nowrap"> </td> <td height="20" width="158" valign="middle"><label> <select name="fearid" id="fearid"> <?php do { ?> <option value="<?php echo $row_fears['FearID']?>"><?php echo $row_fears['FearID']?></option> <?php } while ($row_fears = mysql_fetch_assoc($fears)); $rows = mysql_num_rows($fears); if($rows > 0) { mysql_data_seek($fears, 0); $row_fears = mysql_fetch_assoc($fears); } ?> </select> </label></td> </tr> <tr valign="baseline"> <td height="20" align="right" valign="middle" nowrap="nowrap"> </td> <td align="right" valign="middle" nowrap="nowrap"> </td> <td height="20" valign="middle"></td> </tr> <tr valign="baseline"> <td height="20" align="right" valign="middle" nowrap="nowrap"> </td> <td align="right" valign="middle" nowrap="nowrap"> </td> <td height="20" valign="middle"><label></label> <label></label></td> </tr> <tr valign="baseline"> <td height="25" align="right" valign="middle" nowrap="nowrap"> </td> <td align="right" valign="middle" nowrap="nowrap"> </td> <td height="25" valign="middle"><label></label></td> </tr> </table> <?php do { ?> <table width="310" border="1"> <tr> <td width="101">Current Fears: </td> <td width="193"><?php echo $row_animalFear2['AnimalFearID']; ?></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> <?php } while ($row_animalFear2 = mysql_fetch_assoc($animalFear2)); ?><p> </p> <p> <input name="animalFearid" type="hidden" id="animalFearid" value="<?php echo $totalRows_animalFear +1 ?>" /> <input name="animalid" type="hidden" id="animalid" value="<?php echo $row_animal['AnimalID']; ?>" /> <?php echo $totalRows_animalFear ?> </p> <p> </p> <input type="hidden" name="MM_insert" value="form1"> </form> <p> </p> </body> </html> <?php mysql_free_result($animal); mysql_free_result($animalFear); mysql_free_result($fears); mysql_free_result($animalFear2); ?> Please help me...? Waht am i missing??? Quote Link to comment https://forums.phpfreaks.com/topic/90075-solved-update-record-to-same-page-using-the-form-variable-to-determine-query/#findComment-461845 Share on other sites More sharing options...
yandoo Posted February 8, 2008 Author Share Posted February 8, 2008 Hi all, Got it working!!! Hells bells the line of code mysql_select_db($database_woodside, $woodside); $query_animalFear2 = "SELECT * FROM animalfears WHERE AnimalID='" . $row_animalFears['AnimalID'] . "'"; $animalFear2 = mysql_query($query_animalFear2, $woodside) or die(mysql_error());[code] to.. [code] mysql_select_db($database_woodside, $woodside); $query_animalFear2 = "SELECT * FROM animalfears WHERE AnimalID='" . $row_animalFears'AnimalID'] . "'"; $animalFear2 = mysql_query($query_animalFear2, $woodside) or die(mysql_error()); S on $row_animalFears.... Thanks[/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/90075-solved-update-record-to-same-page-using-the-form-variable-to-determine-query/#findComment-461857 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.