PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 19th, 2004, 01:02 PM
Pineriver Pineriver is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 Pineriver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 12 sec
Reputation Power: 0
Question How to echo form values

Hi, I have a form like this in php on list.php

PHP Code:
echo " <form name=\"form1\" method=\"post\" action=\"sites.php\">";
$i 1;
  while (
$i <= 10){
 echo
"<input type=\"text\" name=\"field$i\"><br>";
$i++;
}
echo 
"</form>"


in sites.php I have

PHP Code:
 $i 1;
  while (
$i <= 10){
echo
"$field$i";
$i++;


The problem is that all I see is the numbers 1 through 10 in sites.php.
My question is how can I echo the variables passed by list.php?
Thanks in advance

Reply With Quote
  #2  
Old June 19th, 2004, 07:46 PM
pocketsized pocketsized is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Brunei
Posts: 26 pocketsized User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
First of all, this:

PHP Code:
 $i 1;
     while (
$i <= 10){
   echo
"$field$i";
   
$i++;
   } 


should be this:

PHP Code:
 $i 1;
     while (
$i <= 10){
   echo
"field$i";
   
$i++;
   } 


field should not have a dollar sign in front of it or else PHP will think it's a variable and try to retreive the value it stores.

Second, you are sending your form via post. Is register_globals on (which, I should add, isn't good for security: http://forums.devshed.com/t20525/s.html). If not, you'll have to access the variables from the $_POST array.

Reply With Quote
  #3  
Old June 19th, 2004, 11:22 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
In list.php you should treat the textboxes as an array. If you want them to be named field but give multiple values, name the textboxes field[]. This will turn it into an array and when the data is passed to sites.php, you can find all your values located in the array $_POST['field'].

Remember, it is an array so you have to iterate it to get all the values. Below is both scripts modified to do just that:

Enjoy:

list.php
PHP Code:
<?php
echo " <form name=\"form1\" method=\"post\" action=\"sites.php\">";
$i 1;
  while (
$i <= 10){
echo
"<input type=\"text\" name=\"field[]\"><br>";
$i++;
}
echo 
'<input type="submit" />';
echo 
"</form>";
?>

sites.php
PHP Code:
<?php
foreach ($_POST['field'] as $field_num => $field_value) {
        print 
"Field #$field_num : $field_value <br />\n";
}
?>
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > How to echo form values


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway