AMPLECOMPUTERS
asked on
Passing variables or constants through a section of php code
Be gentle, I am very new to PHP coding so I am sure there is a simple explination to this I am just missing. I have a long section of PHP code that grabs $_POST information passed from another page. That code works flawlessly up to a point, then my variable $CustID is reset to null, even if I make a constant called custid2 it too is reset at the same point.
Line 3 displays "91"
Lines 5 and 6 display nothing at all.
Line 4 executes after the submit button is clicked on an included form. This is intended to get information from the user, combine information obtained earlier in the code (for example, the $CustID) and use all that information to insert a record into a table.
Ideas?
echo "test1>".$CustID."< <br />";
define("custid2", $CustID);
echo "test1b>".custid2."< <br />";
if (isset($_POST['submit'])) {
echo "test2>".$CustID."< <br />";
echo "test3>".custid2."< <br />";
Line 1 displays "91"Line 3 displays "91"
Lines 5 and 6 display nothing at all.
Line 4 executes after the submit button is clicked on an included form. This is intended to get information from the user, combine information obtained earlier in the code (for example, the $CustID) and use all that information to insert a record into a table.
Ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please post your form, particulare, the HTML for the SUBMIT button.
You could consider storing the variables in a session, so they're available throughout your site. You shouldn't be using DEFINE to set variables - only constants.
When a user submits your form, validate the data and then store the values in the $_SESSION array. You must include session_start() and the beginning of each page in order to access the session functions.
Once you're finished with your session, call session_destroy() to clear all the values.
For more info on session - http://www.w3schools.com/PHP/php_sessions.asp
When a user submits your form, validate the data and then store the values in the $_SESSION array. You must include session_start() and the beginning of each page in order to access the session functions.
Once you're finished with your session, call session_destroy() to clear all the values.
For more info on session - http://www.w3schools.com/PHP/php_sessions.asp
session_start();
$_SESSION['CustID'] = 91;
...
echo $_SESSION['CustID'];
ASKER
That idea worked perfectly. After a little tweaking to your code I got it to work exactly the way I wanted, thanks!