This is a discussion on Variable not passed twixt pages.. within the PHP General forums, part of the PHP Programming Forums category; Greetings learned PHP(eople), Scenario : User fills in text box, pushes Submit and textbox data gets passed to MySQL database.. ============================================= ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Greetings learned PHP(eople),
Scenario : User fills in text box, pushes Submit and textbox data gets passed to MySQL database.. ============================================= The code from the HTML page : <form action="savemail.php" method="GET" target="main"> <input type="text" class="mailinput" name="mailaddress" value="Your Email Address"> ================================================== The code from savemail.php : <?php $result = @mysql_pconnect('localhost', 'user', 'pass'); $query = "insert into email values ('" . $_REQUEST['mailaddress'] .. "')"; //Error stuff------------------------------------------------- $ResSaveMail = mysql_query($query); if (!$ResSaveMail) { echo("<P>Error performing query: " . mysql_error() . "</P>"); echo("Your email has not been saved to the Delta Database."); exit(); } //------------------------------------------------------------ ?> ======================================= THe problem : The variable 'mailaddress' is not getting passed to savemail.php echo $_REQUEST['mailaddress'] reveals blank.... On another programmers advice I tried using POST in my form, but that don`t work either.. The database is getting populated with blank values...is my problem in the php code somewhere..I been playing with this for a while now and no joy has yet surfaced.. Any ideas greatly appreciated... -- Chris Blake Office : (011) 782-0840 Cell : 083 985 0379 Then there was the Formosan bartender named Taiwan-On. |
|
|||
|
$_REQUEST works fine, and is better than $_GET and $_POST because then your
page can work regardless of which method you used when calling it. This is handy if you want to call a page recursively (submit a page to itself). You need to make sure that your session is started on both your origin page and your target page... otherwise session variables such as $_GET, $_POST, an $_REQUEST will never be available on subsequent pages. I use this on my master template page... // SESSION session_name(); session_start(); ini_set("session.cookie_lifetime","120"); My (simplified) template page structure: // SESSION session_name(); session_start(); // INCLUDES require_once("cnxn.php"); require_once("header.php"); // MAIN ... It seems to me that this behaves a little differently than ASP which I only needed to start the session once - not on every page that I navigate to. Can someone shed some light on that? |