Jump to content


This topic is now archived and is closed to further replies.


Forms and Arrays

Recommended Posts

Hello everyone. I am a PHP noob and on the verge of pulling all my hair out!
I am trying to make a web page that uses a simple form that lets you input data and then passes that data in the form of a variable to a PHP file which then displays it on another page. But for some reason i just can't get it to work. Could someone please tell me what i'm doing wrong. Thanks in advance for any help and advice. Clinker

[u]HTML [/u]
<title>My Form</title>
<body text="#0000ff">
<div align="center">
<table width="350" cellpadding="10" cellspacing="0" bgcolor="#fffacd" border="2">
<h4 align="center"><u>Roof Coverings</u></h4>

<form action="http://localhost/myfiles.php/names.php" method=post>

Title: .................... <input type="text" name="YourName">

My real name is:
<input type="text" name="RealName">
<input type="submit" name="submit" value="Submit">

[u]PHP code[/u]
$MyName = array('Colin' , 'David' , 'Peter' , 'Mark' , 'Simon' , 'Paul' , 'Lee');

echo $MyName'Colin';

Share this post

Link to post
Share on other sites
If you want to get the submitted data from the form then you'll do this:

$name = $_POST['YourName'];
$rname = $_POST['RealName'];

echo "HI you're name is " . $name . ", your real name is: " . $rname;


Share this post

Link to post
Share on other sites
Hey that works great Wildteen88 many thanks! But is there anyway to keep the data in the php file once it's been added or until i decide to change it? Thanks again Clinker

Share this post

Link to post
Share on other sites
Greetings Clinker

If you want to have the data available over several pages, or for the complete time that person is accessing the server, you might want to look into using a SESSION.

SESSIONS are kind of a big topic for one post, so you might want to look around a bit. I learned enough about them to use them for multi-page forms from different tutorials and articles on the web.

I hope this helps.

Share this post

Link to post
Share on other sites


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.