Note that there are some explanatory texts on larger screens.

plurals
  1. PO$_SESSION variables lost after button click
    primarykey
    data
    text
    <p>I know this has been asked before, but I can't seem to make this work... I have a PHP form with several text boxes and a button.</p> <p>The button will call different functions, depending on the value of one variable which is declared early on. I realized that the variable was getting lost after the 'Continue' button click, so I had thought that assigning it to a <code>$_SESSION</code> variable might help. NOT!</p> <p>as requested, here is the full code for this page ... as it currently is. Please note, I have tried EVERYTHING suggested from the responses already, even if it is not included in the version as it is now!!..</p> <pre><code>&lt;?php require_once ("Includes/connectDB.php"); session_start(); $pn = $_GET['q']; $hideval = $pn; //values are as expected here...(the calling form has checks in place to ensure valid number entered $query = "SELECT * FROM customer WHERE Phone='$pn'"; $result = mysql_query($query); if (!$result) die ("Database access failed: " . mysql_error()); $rows = mysql_num_rows($result); $rowinfo = mysql_fetch_array($result); $cphone = $pn; if ($rows &gt; 0) { $clast = $rowinfo['LastName']; $cfirst = $rowinfo['FirstName']; $caddr1 = $rowinfo['Address1']; $caddr2 = $rowinfo['Address2']; $cpostal = $rowinfo['Postal']; $ccity = $rowinfo['City']; $cprov = $rowinfo['Province']; $cpay = $rowinfo['PayType']; $corder = $rowinfo['CustOrder']; } else { $clast = ''; $cfirst = ''; $caddr1 = ''; $caddr2 = ''; $cpostal = ''; $ccity = ''; $cprov = 'ON'; $cpay = ''; $corder = ''; } function AddRecord() { $clast = $_POST['CustLastName']; $cfirst = $_POST['CustFirstName']; $cphone = $_POST['CustPhone']; $caddr1 = $_POST['CustAddress1']; $caddr2 = $_POST['CustAddress2']; $ccity = $_POST['CustCity']; $cpostal = $_POST['CustPostal']; $cpay = $_POST['PayType']; $corder = $_POST['CustOrder']; if(! get_magic_quotes_gpc() ) { $cphone = addslashes ($cphone); $clast = addslashes ($_POST['CustLastName']); $cfirst = addslashes ($_POST['CustFirstName']); $caddr1 = addslashes ($_POST['CustAddress1']); $caddr2 = addslashes ($_POST['CustAddress2']); $ccity = addcslashes($_POST['CustCity']); $cpostal = addcslashes($_POST['CustPostal']); $corder = addcslashes($_POST['CustOrder']); } else { $clast = ($_POST['CustLastName']); $cfirst = ($_POST['CustFirstName']); $caddr1 = ($_POST['CustAddress1']); $caddr2 = ($_POST['CustAddress2']); $ccity = ($_POST['CustCity']); $cpostal = ($_POST['CustPostal']); $corder = $_POST['CustOrder']; } $query = "INSERT INTO customer (Phone, LastName, FirstName, Address1, Address2, City, Province, Postal, PayType, CustOrder) VALUES ('$cphone','$clast','$cfirst', '$caddr1', '$caddr2', '$City', '$Province', '$Postal', '$cpay', '$corder')"; $result = mysql_query($query); if (!$result) die ("Database access failed: " . mysql_error()); } function EditRecord() { echo ('Im going to try an edit'); die; $clast = $_POST['CustLastName']; $cphone = $_POST['CustPhone']; $cfirst = $_POST['CustFirstName']; $caddr1 = $_POST['CustAddress1']; $caddr2 = $_POST['CustAddress2']; $ccity = $_POST['CustCity']; $cpostal = $_POST['CustPostal']; $cpay = $_POST['PayType']; $corder = $_POST['CustOrder']; if(! get_magic_quotes_gpc()) { $clast = addslashes ($_POST['CustLastName']); $cfirst = addslashes ($_POST['CustFirstName']); $caddr1 = addslashes ($_POST['CustAddress1']); $caddr2 = addslashes ($_POST['CustAddress2']); $ccity = addcslashes($_POST['CustCity']); $cpostal = addcslashes($_POST['CustPostal']); $corder = addslashes($_POST['CustOrder']); } else { $clast = ($_POST['CustLastName']); $cfirst = ($_POST['CustFirstName']); $caddr1 = ($_POST['CustAddress1']); $caddr2 = ($_POST['CustAddress2']); $ccity = ($_POST['CustCity']); $cpostal = ($_POST['CustPostal']); $corder = $_POST['CustOrder']; } $query = "UPDATE customer SET Phone='$cphone', LastName='$clast', FirstName='$cfirst', Address1='$caddr1', Address2='$caddr2', City='$ccity', Province='$cprov', Postal='$cpostal', PayType='$cpay', CustOrder='$corder' WHERE Phone='$cphone'"; $result = mysql_query($query); if (!$result) die ("Database access failed: " . mysql_error()); } ?&gt; &lt;!DOCTYPE html&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;link rel="stylesheet" type="text/css" href="styles/beer_delivery.css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;&lt;/p&gt; &lt;br&gt;&lt;br&gt; &lt;div id="mainPicture"&gt; &lt;div class="picture"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="contentBox"&gt; &lt;div class="innerBox"&gt; &lt;h1&gt;Customer Information&lt;/h1&gt; &lt;div class="contentText"&gt; &lt;p&gt;&lt;/p&gt; &lt;div id="main"&gt; &lt;form action="customer_info.php" method="post"&gt; &lt;fieldset&gt; &lt;legend&gt;Customer&lt;/legend&gt; &lt;label for="CustPhone"&gt;Phone:&lt;/label&gt; &lt;input type="text" name="CustPhone" id="CustPhone" tabindex="2" value="&lt;?php echo $cphone; ?&gt;"&gt; &lt;br&gt; &lt;div id="divider"&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;label for="CustLastName"&gt;Last Name:&lt;/label&gt; &lt;input type="text" name="CustLastName" id="CustLastName" tabindex="2" value="&lt;?php echo $clast; ?&gt;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;label for="CustFirstName"&gt;First Name:&lt;/label&gt; &lt;input type="text" name="CustFirstName" id="CustFirstName" tabindex="3" value="&lt;?php echo $cfirst; ?&gt;"&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;label for="CustAddress1"&gt;Address 1:&lt;/label&gt; &lt;input type="text" name="CustAddress1" id="CustAddress1" tabindex="4" value="&lt;?php echo $caddr1; ?&gt;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;label for="CustAddress2"&gt;Address2:&lt;/label&gt; &lt;input type="text" name="CustAddress2" id="CustAddress2" tabindex="5" value="&lt;?php echo $caddr2; ?&gt;"&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;label for="CustCity"&gt;City:&lt;/label&gt; &lt;input type="text" name="CustCity" id="CustCity" tabindex="6" value="&lt;?php echo $ccity; ?&gt;"&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;label for="CustPostal"&gt;PostalCode&lt;/label&gt; &lt;input type="text" name="CustPostal" id="CustPostal" tabindex="7" value="&lt;?php echo $cpostal; ?&gt;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;label for="CustProvince"&gt;Province:&lt;/label&gt; &lt;input type="text" name="CustProvince" id="CustProvince" tabindex="8" value="&lt;?php echo $cprov; ?&gt;"&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;label for="CustOrder"&gt;Customer Order:&lt;/label&gt; &lt;textarea name="CustOrder" rows="4" cols="50" tabindex="9"&gt;&lt;?php echo $corder; ?&gt;&lt;/textarea&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;label for="PayType"&gt;Method of Payment:&lt;/label&gt; &lt;select name="PayType" id="PayType" tabindex="10"&gt; &lt;option value="Credit Card" &lt;?php if ($cpay == 'Credit Card') echo ' selected="selected"';?&gt;&gt;Credit Card&lt;/option&gt; &lt;option value="Debit" &lt;?php if ($cpay == 'Debit') echo ' selected="selected"';?&gt;&gt;Debit&lt;/option&gt; &lt;option value="Cheque" &lt;?php if ($cpay == 'Cheque') echo ' selected="selected"';?&gt;&gt;Cheque&lt;/option&gt; &lt;option value="Other"&lt;?php if ($cpay == 'Other') echo ' selected="selected"'; ?&gt;&gt;Other&lt;/option&gt; &lt;/select&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;form id="custform" method="post" action="&lt;?php echo $_SERVER['PHP_SELF']."?".http_build_query($_GET); ?&gt;"&gt; &lt;input type="submit" name="Continue" id="Continue" value="Continue" tabindex="11"&gt; &lt;/form&gt; &lt;?php //have also used session vars here...but same problem echo $_GET['q']; //this shows the phone number if(isset($_POST['Continue'])) { //ultimately, the functions AddRecord and EditRecord will be called in here ... once I get the variable problem fixed echo 'after click: '. $_GET['q']; //this shows "after click: " } ?&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload