473,761 Members | 9,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Arrays in a Form

Hi, I am pretty new on php, and have been trying to solve a problem I
am having for the past 2 days.
I have a HTML page which is going to have a form and some of the
fields in the form will work like a table to allow the user to enter
up to 15 lines on information on 4 columns, this application is to
allow someone to enter a recipe into a database, so we will have 15
lines to allow people to enter: Quantity, Mesasure, Ingredient, and a
flag to indicate if is optional or not.

So I tought that would be better to create a bi-dimensional array and
pass it to the php code that is called when submit is hit. So here is
what I have done:

IN THE HTML FILE:
....
<form action="insert_ recipe.php" method="POST">
<?php
$ingr_array = array(array());
?>
....
some code...
....

<tr>
<td align="center" class="cellbg"> <input type="text" name="<?php
$ingr_array[0][0] ?>" ID="quantity0" size="5"
class="defaultf ont"></td>
<td align="center" class="cellbg"> <input type="text" name="<?php
$ingr_array[0][1] ?>" ID="measure0" size="20"
class="defaultf ont"></td>
<td align="center" class="cellbg"> <input type="text" name="<?php
$ingr_array[0][2] ?>" ID="ingredient0 " class="defaultf ont"
size="27"></td>
<td align="center" class="cellbg"> <input type="checkbox" name="<?php
$ingr_array[0][3] ?>" ID="optional0" class="defaultf ont"></td>
</tr>
// 14 more of this...

and then on my insert_recipe.p hp I am trying to check If I got
something using these debug messages:

echo "Size of array is ".sizeof($ingr_ array)."<BR>";
echo "Quantity is ".$ingr_arr ay[0][0]."<BR>";
echo "Measure is ".$ingr_arr ay[0][2]."<BR>";
echo "Ingredient is ".$ingr_arr ay[0][2]."<BR>";

So when I type any data in the form and hit the submit button, I got
the following displayed:

Size of array is 0
Quantity is
Measure is
Ingredient is

Any idea on what I can be doing wrong here ?

Thanks in advance for any help on this.

M.D.
Jul 17 '05 #1
3 2144
Your input is wrong....try <INPUT NAME='array_nam e[]'>. Ive just
completed something similar and loosley did the following:

Built input form using NAME="array_nam e[]"
Upon submission, IMPLODED the array into a single string:
$arvar=implode( ",",$array_name );
Submitted the resulting variable into the db: SQL="INSERT into tblname
('col_name') VALUES ($arvar)
Reverse to extract from DB/view data...

HTH

Jul 17 '05 #2
*** M.D. escribió/wrote (23 Sep 2004 12:54:48 -0700):
$ingr_array = array(array()); <td align="center" class="cellbg"> <input type="text" name="<?php
$ingr_array[0][0] ?>" ID="quantity0" size="5"


Where do you set the value of $ingr_array?

--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #3
Unless you have register_global s ON you can only reference screen variable
through the $_POST array. What you need to do is this:

$ingr_array = $_POST['ingr_array'];

--
Tony Marston

http://www.tonymarston.net

"M.D." <m6**@hotmail.c om> wrote in message
news:e0******** *************** ***@posting.goo gle.com...
Hi, I am pretty new on php, and have been trying to solve a problem I
am having for the past 2 days.
I have a HTML page which is going to have a form and some of the
fields in the form will work like a table to allow the user to enter
up to 15 lines on information on 4 columns, this application is to
allow someone to enter a recipe into a database, so we will have 15
lines to allow people to enter: Quantity, Mesasure, Ingredient, and a
flag to indicate if is optional or not.

So I tought that would be better to create a bi-dimensional array and
pass it to the php code that is called when submit is hit. So here is
what I have done:

IN THE HTML FILE:
...
<form action="insert_ recipe.php" method="POST">
<?php
$ingr_array = array(array());
?>
...
some code...
...

<tr>
<td align="center" class="cellbg"> <input type="text" name="<?php
$ingr_array[0][0] ?>" ID="quantity0" size="5"
class="defaultf ont"></td>
<td align="center" class="cellbg"> <input type="text" name="<?php
$ingr_array[0][1] ?>" ID="measure0" size="20"
class="defaultf ont"></td>
<td align="center" class="cellbg"> <input type="text" name="<?php
$ingr_array[0][2] ?>" ID="ingredient0 " class="defaultf ont"
size="27"></td>
<td align="center" class="cellbg"> <input type="checkbox" name="<?php
$ingr_array[0][3] ?>" ID="optional0" class="defaultf ont"></td>
</tr>
// 14 more of this...

and then on my insert_recipe.p hp I am trying to check If I got
something using these debug messages:

echo "Size of array is ".sizeof($ingr_ array)."<BR>";
echo "Quantity is ".$ingr_arr ay[0][0]."<BR>";
echo "Measure is ".$ingr_arr ay[0][2]."<BR>";
echo "Ingredient is ".$ingr_arr ay[0][2]."<BR>";

So when I type any data in the form and hit the submit button, I got
the following displayed:

Size of array is 0
Quantity is
Measure is
Ingredient is

Any idea on what I can be doing wrong here ?

Thanks in advance for any help on this.

M.D.

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
9893
by: Jason | last post by:
Currently I have a number of html forms which loop through records in a database table. In order to be able to update the right record when the form is submitted, I've tacked number on to the field names, i.e.: PHP: echo '<input type="text" name="hat_color_'.$i.'" value="'.$currentRow.'"> <input type="text" name="favorite_food_'.$i.'" value="'.$currentRow.'">'; HTML: <input type="text" name="hat_color_0" value="brown"><input
7
5657
by: Gary | last post by:
I haver a table of students - Say 100 students that I need to be able to update/delete and amend. I know I can do this one student at a time which is simple but lets say I want to see all the students on the screen at the same time, modify some, mark some for deletion and even have blank fields at the end to add a new record. In HTML which is generated I label each row and input field with a name/number combination i.e <input type=text...
10
13447
by: Chamomile | last post by:
I have been happily using array members as id's in my html code (either hand coded or generated by server-side script-php ) for some time. eg < input type='text' id='arrayItem' >< input type='text' id='arrayItem' >etc. particlarly in forms for sending input data to be server processed. and also using javascript client-side for dynamic text menu-trees etc. This has worked fine using IE Netscape and Opera as test browsers.
8
2323
by: Greg | last post by:
In VB6 I made heavy use of control arrays I see they have been 'deprecated' in vb.Net, with a questionable explanation that they are no longer necessary which just addresses the event issue! Problem is I commonly associated several other controls with the same index inside the event handler - eg a Directory listbox, Label, Checkbox, Textbox Drivebox etc all associated with identical index. Now I see Control arrays belong to VB6...
1
2691
by: conor.robinson | last post by:
Using large arrays of data I found it is MUCH faster to cast arrays to matricies and then multiply the two matricies togther (scipy.matrix(ARRAY1)*scipy.matrix(ARRAY2)) in order to do a matrix multipy of two arrays vs. scipy.matrixmultipy(ARRAY1, ARRAY2). Are there any logical/efficiency errors with this train of thought and is there a valid reason for the speed increase? Thanks, Conor
16
3497
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 in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown list and checkbox so that they can make changes. I named these elements as arrays and wish to run an...
3
2494
by: assgar | last post by:
I might not be appoaching this correctly because it is not working. I have a function that displays a dynamic form for the user to make one or more selections. There are 5 arrays to collect the 5 pieces of information relelated to each dynamically created rows. I am trying to return the collected information in the 5 arrays to the process so I can use it to insert into a database. <?php /****FORM*****/
6
10188
by: MLH | last post by:
I get the concept of setting an object variable lilke rstCustomers to Nothing (Set rstCustomers = Nothing) But what about other variable types that can consume sizable chunks of memory. For instance, array variables. Is memory automatically released when the called procedure utilizing them goes out-a-scope? Do programmers have to worry about memory leaks that may/might/dunno occur?
1
1852
by: assgar | last post by:
Hello I have changed the process code abit so it receives the data from the form and ensures the data in array format. This has eliminated my previous error. The problem I am experiencing is the looping is not displaying the all contents of the arrays. Do you have any idea what the problem is and how to fix the problem?
19
248254
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect this data is essential to any developer. This article is a basic tutorial on how to user HTML Forms, the most common method of data collection. Assumptions - Basic HTML knowledge. - Basic PHP knowledge. HTML Forms A common and simple way of...
0
9336
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9765
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8770
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.