473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help using two arrays in one foreach

1
I have two arrays:

1)
Expand|Select|Wrap|Line Numbers
  1. $labels = array   ("firstname" => "First Name: ",      //used for labeling a form
  2.                 "lastname" => "Last Name: ",
  3.                 "username" => "User Name: ",
  4.                 "password" => "Password: ",
  5.                 "email" => "Email: "
  6.                 );
  7.  
2)
Expand|Select|Wrap|Line Numbers
  1.  $_POST = array   ("firstname" => "john ",      //normal output from a form
  2.                 "lastname" => "doe ",
  3.                 "username" => "johndoe ",
  4.                 "password" => "john123 ",
  5.                 "email" => "john@email.com "
  6.                 );
I then do some validation. If there is trouble, the form outputs again with this :

Expand|Select|Wrap|Line Numbers
  1. echo "<form action='$_SERVER[PHP_SELF]' method='POST'>";
  2.  
  3.     foreach($labels as $field => $label)
  4.     {
  5.         echo "<label for='$field'>$label</label>
  6.                 <input type='text' name='$field' id='$field' value='$value'/>\n";
  7.     }
  8.     echo "<div id='submit'><input type='submit' value='Submit' />\n";
  9.     echo "</form>\n</body>\n</html>";
  10.  echo "There were errors with the data you provided:\n";
  11.  
The problem with this is every time the form is re-outputted the error message pops up, but all the information disappears. The reason this is happening is because as the form is being redisplayed, the $value variable is not being reset with the $_POST data. Is there anyway i can use a foreach statement to both output the form labels, and set the $value variable with the data stored in $_POST?
Jan 10 '13 #1
0 1351

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jennifer Lee | last post by:
Hello, I have a rather simple function I've been using in 7.3.4 version ------------------------------------------------------------------------ ----------------- PostgreSQL 7.3.4 on...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
0
by: antique | last post by:
iam supposed to CREATE A FUNCTION INT ADJUSTEDSUM (INT,INT) 1. find the sum of the array of size 100 2. find the number of occurrence of a MIN and MAX number if its twice or more only use 1...
3
by: xxbabysue123xx | last post by:
The question says: Using arrays use the Die class to roll the die 10 times and print the list of values that were stored in the array. Determine the smallest and largest number stored in the array....
3
Blackout
by: Blackout | last post by:
Hi, I'm new to C and need to make a program that displays the output of the first six powers of 2 like this: 1 2 4 8 16 32 (2 to the power of 0, 2 to the power of 1, 2 to...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
2
by: theblissfulwizard | last post by:
FYI - New to ASP I'm trying to get multiple values from checkboxes inserted into a table using arrays. I'm using VBscript - ASP 1.1 (not 2.0) and here is what I want to do. I have a page that...
3
by: SM | last post by:
Hello, I have an array that holds images path of cd covers. The array looks like this: $cd = array( 589=>'sylver.jpg', 782=>'bigone.jpg', 158=>'dime.jpg' );
1
by: James Brown | last post by:
Hi, I'm fairly new to VBA and was looking to start using arrays to calculate medians of monte carlo simulations. I know how to set up an array as I have been reading through such websites as: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.