Displaying form data in new browser window

Hello all.
I am a complete newbie when it comes to php and I have been looking for a way to use an html form to supply information to a separate existing php page.

I want to create a lineup or roster page from the values supplied in an html form. Currently I have a html page with a form using the following form code:

<form name="lineupform" action="roster.php" method="get">
<p>
Name:&nbsp;<input type="text" size="20" name="n1" id="n1"><br /><br />
Name:&nbsp;<input type="text" size="20" name="n2" id="n2"><br /><br />
Name:&nbsp;<input type="text" size="20" name="n3" id="n3"><br /><br />
<input TYPE="SUBMIT" CLASS="button" value="SUBMIT LINEUP" />&nbsp;&nbsp;<input type="reset" value="RESET LINEUP" class="button2" /></p>
</form>

Then roster.php, after the usual html declarations and tags, has the following that I am trying to use to display the data:
[php]

<?php echo $_GET['d1']; ?>
<?php echo $_GET['d2']; ?>
<?php echo $_GET['d3']; ?>

[/php]

But when I complete the form page and hit submit I get a blank roster.php page.

Any help would be appreciated.

That’s because your form names are not d1,d2,d3. They are n1,n2,n3.

Thanks for the less insulting reply this time Kevin.

The names all match and I still get nothing but a blank page. The url in the browser window looks like it is displaying both the page name and the form input names with their input. It reads lineup.php?n1=z&n2=x&n3=b&n4=. But the page itself is blank.

In my defense, you used the wrong terminology on the other forum. Any programmer would have read it the way I did.

I dont know what your doing but this works…

[php]<?php
if($_GET){
echo “{$_GET[‘n1’]}
”;
echo “{$_GET[‘n2’]}
”;
echo “{$_GET[‘n3’]}
”;
}
?>

Name: 

Name: 

Name: 

  

[/php]

Is there some reason you are using GET instead of POST?

No sir.
I am using GET because it was used in an example I found that resembled what I was trying to accomplish.
My code does not have the if statement and echoes set up that way. I will make that change and see if that works for me.

Does a null value have a negative effect on it? I have more text inputs than I may use from day to day.

Edited to add:
Made the change using the if statement and still getting the same results.
The page the form redirects to is still blank.

Let me add some detail to the overall picture in case it matters.
The resulting php page is displayed in a separate browser window on a second monitor. The form html page is on a different monitor. The way my form html is written now it redirects monitor 1 (the form monitor/browser) to the php page. However I have a meta refresh on the page to update the browser on the second monitor.

Does a null value have a negative effect on it

Yes. You need to check if the value is empty or not. You should probably be using POST.
[php]<?php
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’)
{
if (!empty($_POST[‘n1’]))
{
echo “{$_POST[‘n1’]}
”;
}

if (!empty($_POST['n2']))
    {
    echo "{$_POST['n2']}<br>";
    }

if (!empty($_POST['n3']))
    {
    echo "{$_POST['n3']}<br>";
    }
}

?>[/php]

Progress!
Thanks for taking the time to help with this Kevin.

I am getting a display on the php page now. But it is not the text inputs from the form.
instead it is
":} if (!empty($_POST[‘n2’])) { echo "{$_POST[‘n1’]}
and that repeats down the page without breaks incrementing the “n” each time until it gets through them all and ends with "; } } ?>

Again, don’t know what your doing. Copy this code completely and run it exactly as is.

* You are running this on a server with a .php extension right?

[php]<?php
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’)
{
if (!empty($_POST[‘n1’]))
{
echo “{$_POST[‘n1’]}
”;
}

  if (!empty($_POST['n2']))
     {
     echo "{$_POST['n2']}<br>";
     }

 if (!empty($_POST['n3']))
     {
     echo "{$_POST['n3']}<br>";
     }
 }

?>

Name: 

Name: 

Name: 

  

[/php]

The form page is a html page and the results page is a php page.
I am running them locally from an AMPPS folder with Apache, php 5.5, and MySql running.

Run what I posted in one php page.

Ok I copied and pasted your code into a file called test.php. Just your code, nothing else.
Placed it in the www folder in the AMPPS directory.
Launched it in Chrome and it displayed the code.

That is not the server directory. You need to put it in the www directory.

C:\Program Files (x86)\Ampps[b]www[/b]

You should be viewing the file at localhost/test.php

It is in the www directory. I called it folder in my reply.
Using the url instead of clicking on it in explorer gets me the right thing.

Now the result is the text I input followed by the form elements. So it works as it should had I done it right initially.

Now I just need to split it into two pages and add some styling to the php page.

Thank you again for the help with this.

Edited to add:
Split was successful. I guess the problem all along was my using c: as the path instead of localhost.

Sponsor our Newsletter | Privacy Policy | Terms of Service