johnseito Posted July 26, 2008 Share Posted July 26, 2008 I created a userinput form for user input, and inputresult to show the use input. I use header so that I can add conditions that if all the field is filled, then go to inputresult to show all the field enter. while using header, I use GET instead of POST b/c post can't pass the variable to a header. But this doesn't work either. The result is completely blank. Here is the user input page PHP Code: <?php if (isset($_GET['TEST'])) { header( "Location: http://localhost/inputresult.php" ); } ?> <form method="GET" action=""> <input type="text" name="username"> <input type="password" name="password"> <br> <input class="gray" type="submit" name="TEST"/> Here is the input result page PHP Code: <?php print"<br>"; echo $_GET['username']; echo $_GET['password']; print"<br>"; ?> <a href="http://localhost/userinput.php">user input</a> the result page is still BLANK AFTER THE GET instead of POST. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/ Share on other sites More sharing options...
paul2463 Posted July 26, 2008 Share Posted July 26, 2008 you are not sending the $_GET data to the new page........... Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/#findComment-600338 Share on other sites More sharing options...
paul2463 Posted July 26, 2008 Share Posted July 26, 2008 try something like <?php if (isset($_GET['TEST'])) { header( "Location: http://localhost/inputresult.php?username=".$_GET['username']."&password=".$_GET['password'] ); } ?> <form method="GET" action=""> <input type="text" name="username"> <input type="password" name="password"> <br> <input class="gray" type="submit" name="TEST"/> Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/#findComment-600340 Share on other sites More sharing options...
johnseito Posted July 27, 2008 Author Share Posted July 27, 2008 try something like This code that you have on top didn't work because action="", so the userinput.php page is not going to show. Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/#findComment-600653 Share on other sites More sharing options...
paul2463 Posted July 27, 2008 Share Posted July 27, 2008 if you dont have an action it goes back to itself, when that happens it sees that $_GET[test] has been set and then places the $_GET variables into the forwarding address and sends that page, your userinput page then recieves the address with the $_GET variables attached and does what you asked it to by echoing out the variables........works perfectly on my machine!! Did you try it before denouncing it??? Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/#findComment-600762 Share on other sites More sharing options...
johnseito Posted July 27, 2008 Author Share Posted July 27, 2008 Yup, I did try it. Can you try it again, but refresh your page after you update your code. Here is my code and it didn't work for me. userinput.php <?php if (isset($_GET['TEST'])) { header( "Location: http://localhost/userinput.php?" . $_POST['username'] . "&" . $_POST['password'] ); } ?> <form method="GET" action=""> <input type="text" name="username"> <input type="password" name="password"> <br> <input class="gray" type="submit" name="TEST"/> resultinput.php <?php print"<br>"; echo $_GET['username']; echo $_GET['password']; print"<br>"; ?> <a href="http://localhost/userinput.php">user input</a> Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/#findComment-600776 Share on other sites More sharing options...
paul2463 Posted July 27, 2008 Share Posted July 27, 2008 here we go... I am trying to help you....when i asked if you had tried something, i didnt ask if you had changed it and tried it, i asked if you had tried it....you said YES...can you explain to me then why you changed my code header( "Location: http://localhost/inputresult.php?username=".$_GET['username']."&password=".$_GET['password'] ); to your code header( "Location: http://localhost/userinput.php?" . $_POST['username'] . "&" . $_POST['password'] ); things wrong in your line of code:- 1. you are not POST'ing anything you are still using GET 2. If you dont tell it what to store the POST or GET variables as, you cannot pull them on the other side can you try the code i origonally sent you and see if that works for you - unchanged then we can move on from there Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/#findComment-600785 Share on other sites More sharing options...
johnseito Posted July 27, 2008 Author Share Posted July 27, 2008 2. If you dont tell it what to store the POST or GET variables as, you cannot pull them on the other side so how does that code that I have not store the variables? The difference is that you added this header( "Location: http://localhost/inputresult.php?username=".$_GET['username']."&password=".$_GET['password'] ); what I highlighted in red. your code works but I think there is two problem with it, one is that I have a lot of conditions or the fields, example if not all the field is enter to highlight the word next to the field red and don't post on the next page inputresult.php But because when I use your header, sometimes my conditions didn't work, when a field is left blank it still show the inputresult.php page. possible reason why : I think it has to do with the url holding the variables, even if some fields are blank it is still redirecting it to the other page and show what was posted. I then did a test to see why is that, so I delete the header, and in the url it still show a bunch of http://localhost/userinput.php?firstname=firstname&lastname= lastname&gender=&month=&dd=dd&yyyy=yyyy&country=&address=&state=-Enter+State- &pt=&em=&username=&psswrd=&repsswrd=&TEST=submit when it should be showing only http://localhost/userinput.php Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/#findComment-601071 Share on other sites More sharing options...
johnseito Posted July 28, 2008 Author Share Posted July 28, 2008 paul2463-- the reason why I have my code wrong from yours is because I kinda of know that code too, but I wasn't sure so I thought I had it right and so I was looking at your code so quickly and not in details that I thought you have the same code, so I just used what I have and it was WRONG. my fault. can you see if you can address my problem I have on top with your new code. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/#findComment-601211 Share on other sites More sharing options...
paul2463 Posted July 28, 2008 Share Posted July 28, 2008 change your user input form to a post form <?php if (isset($_POST['TEST'])) { //remove all empty fields from the $_POST array and create a new array foreach($_POST as $key => $var) { if($var != "") { $address[$key] = $var; //contains all the fields that were NOT empty } } //start to create the header $header = "Location: http://localhost/userinput.php?"; if(count($address)>0) //if the address array has 1 or more fields in it { foreach($address as $key => $var) { $header.="$key=$var&"; //add each one to the header address } //remove the last ampersand $header = substr($header, 0 , -1); } else { //otherwise just remove the "?" from the header address $header = substr($header, 0 , -1); } //send them to the new header with all the new $_GET variables attached header( $header ); // } ?> <form method="POST" action=""> <input type="text" name="username"> <input type="password" name="password"> <br> <input class="gray" type="submit" name="TEST"/> I know that alot of the stuff could be combined to make the code small in size, but its easier to explain the way I have typed it I think Quote Link to comment https://forums.phpfreaks.com/topic/116739-result-completely-blank/#findComment-601562 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.