473,394 Members | 1,693 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,394 software developers and data experts.

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="defaultfont"></td>
<td align="center" class="cellbg"><input type="text" name="<?php
$ingr_array[0][1] ?>" ID="measure0" size="20"
class="defaultfont"></td>
<td align="center" class="cellbg"><input type="text" name="<?php
$ingr_array[0][2] ?>" ID="ingredient0" class="defaultfont"
size="27"></td>
<td align="center" class="cellbg"><input type="checkbox" name="<?php
$ingr_array[0][3] ?>" ID="optional0" class="defaultfont"></td>
</tr>
// 14 more of this...

and then on my insert_recipe.php 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_array[0][0]."<BR>";
echo "Measure is ".$ingr_array[0][2]."<BR>";
echo "Ingredient is ".$ingr_array[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 2129
Your input is wrong....try <INPUT NAME='array_name[]'>. Ive just
completed something similar and loosley did the following:

Built input form using NAME="array_name[]"
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_globals 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.com> wrote in message
news:e0**************************@posting.google.c om...
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="defaultfont"></td>
<td align="center" class="cellbg"><input type="text" name="<?php
$ingr_array[0][1] ?>" ID="measure0" size="20"
class="defaultfont"></td>
<td align="center" class="cellbg"><input type="text" name="<?php
$ingr_array[0][2] ?>" ID="ingredient0" class="defaultfont"
size="27"></td>
<td align="center" class="cellbg"><input type="checkbox" name="<?php
$ingr_array[0][3] ?>" ID="optional0" class="defaultfont"></td>
</tr>
// 14 more of this...

and then on my insert_recipe.php 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_array[0][0]."<BR>";
echo "Measure is ".$ingr_array[0][2]."<BR>";
echo "Ingredient is ".$ingr_array[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
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...
7
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...
10
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...
8
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!...
1
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...
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...
3
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...
6
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...
1
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...
19
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...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
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...

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.