Current location: Hot Scripts Forums » Programming Languages » PHP » $_POST with index


$_POST with index

Reply
  #1 (permalink)  
Old 09-06-04, 03:36 AM
dsidir dsidir is offline
New Member
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
$_POST with index

I am trying to pass some data from a form to another page. In the destination page I want to get the data with $_POST and check if the fields are filled or not .if a field is not filled , the it takes the value of zero . I am trying to do this with loop for because I have 32 form values but even if I write something to the fileds I always get the value of zero...The check code is here:

//check form fileds
for ($i=18;$i<=49; $i++) {
if (isset($_POST['r$i']))
$v[$i]=$_POST['r$i'];
else
$v[$i]="0";
}

Can anyone help ?
Reply With Quote
  #2 (permalink)  
Old 09-06-04, 03:46 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
using single quotes in this: $_POST['r$i']
will cause the engine to NOT to evaluate the value of $i !
instead use double quotes
PHP Code:

//check form fileds

for ($i=18;$i<=49$i++) {
   if (isset(
$_POST["r$i"]))
      
$v[$i] = $_POST["r$i"];
   else
      
$v[$i] = 0;

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 09-06-04, 05:57 AM
dsidir dsidir is offline
New Member
 
Join Date: Sep 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
worked

Thank you , it worked
Reply With Quote
  #4 (permalink)  
Old 09-06-04, 09:27 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
you are welcome
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 09-06-04, 09:57 AM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
I know the other code worked for you but you might want to try this because this will be more reusable.

PHP Code:

foreach($_POST as $key => $value){

        if(empty(
$value))
              
$_POST[$key] = 0;

__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Link to index (PR5) or the forum (PR6) iKwak HTML/XHTML/XML 0 08-26-04 03:35 AM
show index strikefighter HTML/XHTML/XML 0 04-07-04 03:07 AM
please help to paginate index of listing sona PHP 0 12-27-03 08:35 PM
looking for a link index script :S stepper PHP 3 08-26-03 04:27 AM
where is the poll/survey at index page? prettypretty Hot Scripts Forum Questions, Suggestions and Feedback 3 06-12-03 07:30 PM


All times are GMT -5. The time now is 04:25 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.