Jump to content

result completely BLANK


johnseito

Recommended Posts

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?

Link to comment
Share on other sites

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"/>

Link to comment
Share on other sites

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???

Link to comment
Share on other sites

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>

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.