drayarms Posted June 20, 2011 Share Posted June 20, 2011 Here is a simplified version of a script which I named register.php that processes user input from a registration form. <?php if (isset($_POST['submitted'])) { $firstname = mysql_real_escape_string($_POST['firstname']); $lastname = mysql_real_escape_string($_POST['lastname']); header("Location: register_confirm_page.php?firstname=$firstname&lastname=$lastname"); } ?> As intended, the firstname and lastname posted variables are carried over to a redirected page register_confirm_page.php where the user is supposed to review his registration details before clicking the final submit button to be registered. Below is a simplified version of the register confirm page: So far everything works just fine as intended. <?php //Retrieve variables from previous page $firstname=$_GET['firstname']; $lastname=$_GET['lastname']; //Show user his details echo "Firstname:" .$firstname. "<br/>" ; echo "Lastname:" .$lastname //Show the submit button. echo'<form method="post" action="register_confirm.php?firstname=$firstname&lastname=$lastname"> <input type="submit" name="submit" value="Register!" /> </form> '; ?> Now the intent is to send the first name and last name to yet another page register_confirm.php, where the value is finally submitted into my database. To keep it simple, I won't include this third page, but what I basically did there was use the GET method as above, to retrieve the values again. Well this time around, the first and last names are not sent to the third page. Instead, the literal values '$firstname' and '$lastname' are passed through the url to the third page and I know this because that's what shows up in the url when I click the submit button and that's also what shows up in my database table. Does anyone understand why this may be happening and not what I expected would happen? I have passed variables between more than 2 pages before but this is the first time I am encountering this problem. I really can't see what is being done wrong here. Perhaps someone can. Quote Link to comment Share on other sites More sharing options...
trq Posted June 20, 2011 Share Posted June 20, 2011 Variables are not interpolated within single quotes. Quote Link to comment Share on other sites More sharing options...
AMcHarg Posted June 20, 2011 Share Posted June 20, 2011 Variables in double quotes "$variable", will use the correct value, but in single quotes '$variable' will literally return the string $variable. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 20, 2011 Share Posted June 20, 2011 As suggested by the others, the single quotes in the last echo statement make it so $firstname and $lastname won't work: echo'<form method="post" action="register_confirm.php?firstname=$firstname&lastname=$lastname"> You could change it to a double quote or do something like: echo'<form method="post" action="register_confirm.php?firstname=' . $firstname . '&lastname=' . $lastname . '"> Quote Link to comment Share on other sites More sharing options...
trq Posted June 20, 2011 Share Posted June 20, 2011 There's a hell of an echo in here. Quote Link to comment Share on other sites More sharing options...
fugix Posted June 20, 2011 Share Posted June 20, 2011 There's a hell of an echo in here. Yeah. No need to repeat something that's already been said. OP, if you need further assistance with this let us know and we will be glad to help Quote Link to comment Share on other sites More sharing options...
trq Posted June 20, 2011 Share Posted June 20, 2011 Yeah. No need to repeat something that's already been said. But wait, isn't that your favourite trick fugix? Quote Link to comment Share on other sites More sharing options...
fugix Posted June 21, 2011 Share Posted June 21, 2011 Truthfully, when I first came to this forum yes, now no Quote Link to comment Share on other sites More sharing options...
.josh Posted June 21, 2011 Share Posted June 21, 2011 Truthfully, when I first came to this forum yes, now no But... You just did that even right now, with this: There's a hell of an echo in here. Yeah. No need to repeat something that's already been said. OP, if you need further assistance with this let us know and we will be glad to help You just repeated someone else alluding to not repeating things... Quote Link to comment Share on other sites More sharing options...
litebearer Posted June 21, 2011 Share Posted June 21, 2011 who's on first? Quote Link to comment Share on other sites More sharing options...
fugix Posted June 21, 2011 Share Posted June 21, 2011 Truthfully, when I first came to this forum yes, now no But... You just did that even right now, with this: There's a hell of an echo in here. Yeah. No need to repeat something that's already been said. OP, if you need further assistance with this let us know and we will be glad to help Can't argue with that. You just repeated someone else alluding to not repeating things... Can't argue with that. I did the very thing I said you shouldn't do. My bad Quote Link to comment 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.