palash4003 Posted December 23, 2011 Share Posted December 23, 2011 I have a form, where I'm collecting registration info - like name, address, email, password. I'm calling another php file at server side code, where it will check whether the email exists or not. Pretty simple, just receiving those post variables and check with the database. The issue, if I find a match, I want to go back to the registration.php page, using the following code: if ($email_already_use == "y") { $_SESSION['ERROR'] = "Error"; $_SESSION['MESSAGE'] = "This email address already used. Please try another"; header("location: ".$settings['site_url']."registration.php"); exit; } Now, I would like to place the user input at the registration.php file, but I do not want to use pass variable at URL like this: header("location: ".$settings['site_url']."registration.php?".name=$name&address=$address&email=$email; Is there anyway, I can retrieve those variables at registration.php, without specifying .name=$name&address=$address&email=$email ? Thanks for your help. I see some sites has similar implementation, but did not find anything like how to do it. Quote Link to comment https://forums.phpfreaks.com/topic/253754-how-to-pass-php-variables-without-specifying-in-the-header-location/ Share on other sites More sharing options...
SergeiSS Posted December 23, 2011 Share Posted December 23, 2011 Why do you like to jump from one script to another? Do it in one script! It's more easy. Here http://www.phpfreaks.com/forums/index.php?topic=350489.0 I told about approximately the same task. Quote Link to comment https://forums.phpfreaks.com/topic/253754-how-to-pass-php-variables-without-specifying-in-the-header-location/#findComment-1300862 Share on other sites More sharing options...
palash4003 Posted December 23, 2011 Author Share Posted December 23, 2011 Thanks SergeiSS. You are great! Simple solution and that works for me. Quote Link to comment https://forums.phpfreaks.com/topic/253754-how-to-pass-php-variables-without-specifying-in-the-header-location/#findComment-1300874 Share on other sites More sharing options...
palash4003 Posted December 23, 2011 Author Share Posted December 23, 2011 Hi SergeiSS, Thanks for your prompt reply with the page link. There is only one issue here: If I go to the registration page first time, it is all these messages - like "Name is invalid" whatever I put at echo message. It's only I want when user click on the submit button. By the way, I have a image button, instead of submit like type="image" <?php $name = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : ""; if ($name == "") { echo "Name is invalid<br>"; } ?> Any more help? I appreciate. Quote Link to comment https://forums.phpfreaks.com/topic/253754-how-to-pass-php-variables-without-specifying-in-the-header-location/#findComment-1300880 Share on other sites More sharing options...
Pikachu2000 Posted December 23, 2011 Share Posted December 23, 2011 You need to check whether the form has been submitted before validating the fields in it. Additionally, you'd be best to store errors in an array for display, rather than echoing them randomly in the code. if( strtolower($_SERVER['REQUEST_METHOD']) === 'post' ) { // form has been submitted, validate fields } Quote Link to comment https://forums.phpfreaks.com/topic/253754-how-to-pass-php-variables-without-specifying-in-the-header-location/#findComment-1300882 Share on other sites More sharing options...
SergeiSS Posted December 23, 2011 Share Posted December 23, 2011 In addition to Pikachu's answer. Another possibility to check if the form was submitted is to check POST array, look for the name of your submit button. For example, you have submit with the name "ok". if( isset( $_POST['ok'] ) ) { // do whatever you wish, this block is processed if OK button is pressed } Moreover, you may have more than 1 submit in one form and you may detect the pressed button. Let's assume that your form contains these 2 submits <input type="submit" name="ok" value="Save" /> <input type="submit" name="del" value="Delete" /> Inside processing part your may write if( isset( $_POST['ok']) ) // ok is pressed { // do whatever when Save is pressed } elseif( isset( $_POST['del'] ) ) // del is pressed { // write a code for Delete processing } Hope it helps Quote Link to comment https://forums.phpfreaks.com/topic/253754-how-to-pass-php-variables-without-specifying-in-the-header-location/#findComment-1300912 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.