Jump to content


Forms and Arrays

  • Please log in to reply
4 replies to this topic

#1 Clinker

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 April 2006 - 11:37 AM

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

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

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

echo $MyName'Colin';

#2 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 April 2006 - 11:52 AM

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;


#3 Clinker

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 April 2006 - 01:54 PM

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

#4 freshrod

  • Members
  • PipPip
  • Member
  • 25 posts

Posted 19 April 2006 - 02:06 PM

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.
Nothing is foolproof to a talented fool.

#5 Clinker

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 April 2006 - 02:10 PM

Thanks Freshrod i'll have a look around mate.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users