This seems like such a simple problem but it’s been frustrating me for days!
There are 3 pages involved.
Page 1: user selects a location and is directed to 2nd page
Page 2: location selected from page 1 is displayed, user completes form with further data and is directed to page 3.
Page 3: all records for selected location is displayed, user has option to return to Page 2 to insert another record.
What happens is Page 1 works, Page 2 works, Page 3 doesn’t doesn’t “catch” the variable.
Here’s what I have (I’m not including Page 1 because there’s no issue with it)
Page 2:
<?php require_once('../Connections/conn_taylor.php');
$loc = $_POST['locID'];
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 testname (locID, name, number) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['locID'], "int"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['number'], "text"));
mysql_select_db($database_conn_taylor, $conn_taylor);
$Result1 = mysql_query($insertSQL, $conn_taylor) or die(mysql_error());
?>
<form action="test3a.php?locID=<?php echo $_POST['locID']" name="form1" method="POST">
<p>page 2a </p>
<p>Add name to # <?php echo $loc; ?>
<input name="locID" type="hidden" id="locID" value="<?php echo $loc; ?>"></p>
Name: <input name="name" type="text" id="name>
Number: <input name="number" type="text" id="number
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<input type="hidden" name="MM_insert" value="form1">
</form>
Page 3:
<?php
$loc = $_POST['locID'];
?>
<form action="test2a.php?locID=<?php echo $loc; ?>" name="form1" method="POST">
<p>Page 3</p>
<p>the location is <?php echo $loc; ?>
<input name="locID" type="hidden" id="locID" value="<?php echo $loc; ?>">
</p>
<p>go to page 2
<input type="submit" name="Submit" value="Submit">
</p>
</form>
I have done so many permutations of this, this is just the current one. I have had it working to page 3 where the location is displayed but going back to page 2 gets an error message. Other times it all seems to work, going from page to page with no problems, but the data isn’t inserted into the table. I’m about to go crazy! Any and all help appreciated, for the sake of my sanity.
Oh yes, the title of this post is one of my questions: I’m not sure whether page 2 should have the locID variable in the form action or pass it in a hidden field. I’ve tried both/and with sketchy results. My main problem at this point is why isn’t Page 3 catching the variable?