473,503 Members | 9,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Someone please explain what this does?

I have been looking through this script and came across something that I
dont quite understand how it functions or is used. Basically its brackets
that are added on at the end of a form field value.

EXAMPLE:
<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>">

in other words what does the [] brackets pass to the function thats
processing the form, basically how is the [] used.

Also here is the part of the script that is processing it., as well as the
more coding of the originating form code
===================
// UPDATE BASKET QUANTITY
if (isset($_POST["UpdateChg"])) {

session_start();
include "functions_cart.php";

$i = 0;
$size = count($_POST["eid"]);

for ($i = 0; $i <= $size-1; $i++) {

// call remove bad characters function
$badsymbols = array(" ","-","+","*","/",".");
$_POST["newquan"][$i] = str_replace($badsymbols,"",
$_POST["newquan"][$i]);

if (is_numeric($_POST["newquan"][$i])) {

// if any quantity's equal 0 then remove from cart
if ($_POST["newquan"][$i] == 0) {
unset($_SESSION["cart"][$_POST["eid"][$i]]);
}

// update quantity in cart.
if (array_key_exists($_POST["eid"][$i], $_SESSION["cart"])) {

add_item_to_cart($_POST["eid"][$i], $_POST["newquan"][$i]);

}

} // END IF NUMERIC

}

header ("location:".$_SERVER['HTTP_REFERER']);

} // END BASKET QUANTITY
==============================
===========================
MORE OF THE FORM CODE

<td class="dividingborder"><input name="newquan[]" type="text"
id="newquan[]3" value="<? echo $ses_quan; ?>" size="5" maxlength="4">
<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id;
?>"></td>
===========================

Apr 1 '06 #1
3 1386
Chris H wrote:
I have been looking through this script and came across something that I
dont quite understand how it functions or is used. Basically its brackets
that are added on at the end of a form field value.

EXAMPLE:
<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>">


Instead of sending variables you send arrays, this is specially good if you
have a list where you can select more than one option.

Arrays can be easier to handle as you can loop through them and preform a task
on them all, while using single variables, you will need to it "manually" for
each.

for($i=0;$i<count($array);$i++) {
$array[$i]=fix($array[$i]);
}

vs

$variable0=fix($variable0);
$variable1=fix($variable1);
$variable2=fix($variable2);
$variable3=fix($variable3);
$variable4=fix($variable4);
$variable5=fix($variable5);
$variable6=fix($variable6);
$variable7=fix($variable7);
$variable8=fix($variable8);
$variable9=fix($variable9);
$variable10=fix($variable10);
$variable11=fix($variable11);
$variable12=fix($variable12);

But the code will be easier to follow if you use single variables (if you name
them properly).
//Aho
Apr 1 '06 #2
Chris H wrote:
I have been looking through this script and came across something that I
dont quite understand how it functions or is used. Basically its brackets
that are added on at the end of a form field value.

EXAMPLE:
<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>">

in other words what does the [] brackets pass to the function thats
processing the form, basically how is the [] used.


PHP sees these types of variables upon submission, and counts them as
variables. You can have twenty items named eid[] and, when the user
presses the Submit button, PHP gets them in $_POST[] as an array. So,
in this case, it would be $_POST['eid'][0] through whatever is the
highest element of the array.

It makes for things that just aren't possible (well, they are possible,
but very tedious to do) without using array functionality in HTML forms.

http://www.webmasterworld.com/forum88/1204.htm is a start, but you can
find a whole world more of information from Google.

You can also explicitly name arrays within your HTML code and PHP will
get them and do the "right thing" with them when the request is sent.
It's actually quite nice.

HTH,
Mike
Apr 1 '06 #3
Chris H wrote:
===========================
MORE OF THE FORM CODE

<td class="dividingborder"><input name="newquan[]" type="text"
id="newquan[]3" value="<? echo $ses_quan; ?>" size="5" maxlength="4">
<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id;
?>"></td>
===========================


Note that you can also have names like foo[bar] and foo[bar2]. This will
work the same as foo[]. It is best to think of these as arrays.
Apr 1 '06 #4

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

Similar topics

8
1944
by: Igor Raytsin | last post by:
Hello All, The following script is reproducing the problem assuming you have Northwind database on the server. Please note it gives you the error message on line 12. USE tempdb GO...
5
2786
by: J Allen Horner | last post by:
I'm just starting to learn C, and the tutorial I'm reading uses this code as an example: ----------- #include <stdio.h> #define MAX 10 int a; int rand_seed=10;
0
2109
by: Ian | last post by:
I've been doing some component development recently, and I'm confused as to exactly what MergablePropertyAttribute does. The .NET docs say: Properties that are marked with MergableProperty(true)...
5
1449
by: klj_mcsd | last post by:
Let's say you set txtlastname1.visible = true Then DirectCast(Page.FindControl("txtLastName1"), TextBox).Visible = False Why when you check txtlastname1.visible it is equal to True?
4
1073
by: Merlin | last post by:
Hey All, I`ll Pay someone to tell me this now, as its doing my head in, I carn`t see out on the net and no one seems to know! I have a form that connects to a Access database, and I have a...
1
2739
by: Simon Windsor | last post by:
Hi I have just recevived this error could not write to hash-join temporary file: No space left on device Can someone please explain how I can stop this occuring. Whereis the hash-join...
5
2010
by: garyusenet | last post by:
I understand that Point is an object used for storing co-ordinates, such as mouse location. I can't figure out what the e's do in the above example can someone explain please. Thanks, Gary.
9
2086
by: colin.mcnulty | last post by:
Hi, I'm a SQL Server DBA, but I guess that won't buy me any friends round here huh? ;-) I've been asked to look at the SQL that's being executed on a DB2 database from a web app, specifically...
2
4841
by: blueyonder | last post by:
The statament below does exactly what I want it to do but I don't understand why? In my mind the subquery produces a result set which is a subset of the handset table which the initial part of...
1
2384
by: td0g03 | last post by:
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be...
0
7207
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
7095
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
7294
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
7470
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
5602
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,...
0
3183
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...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.