473,657 Members | 2,405 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($ba dsymbols,"",
$_POST["newquan"][$i]);

if (is_numeric($_P OST["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_exis ts($_POST["eid"][$i], $_SESSION["cart"])) {

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

}

} // END IF NUMERIC

}

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

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

<td class="dividing border"><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 1397
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<cou nt($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="dividing border"><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
1954
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 sp_addlinkedserver 'Test17'
5
2793
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
2116
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) can be combined with properties belonging to other objects in a Properties window. Properties that are marked with MergableProperty(false) must be displayed separately. The default is true. Does this mean that if you're working in a designer...
5
1460
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
1082
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 combo box on this form (this combo box has a list of Access Levels, a user would be able to choose one Access Level out of the combo box). The combo box is serving double duty, as they usually do, it is giving me a
1
2757
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 temporary file? How can I make it big? etc. The query question runs fine in Oracle, MySQL and Postgres normally, but I
5
2024
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
2100
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 when the web site does XYZ, what SQL does it run on the DB2 database? Unfortunately everyone who knew about how it works has left and I've never even seen a DB2 database before today! So, I appear to be looking at an IBM DB2 Universal Database...
2
4851
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 the query is then applied to. However, the 'select all from Sim where it doesn't exists' is the bit I don't get where what doesn't exist? how is the comparison made? I haven't specified a parameter etc.. Any help would be much appreciated.
1
2394
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 great. I know its sorta long, but maybe you only have to few the first few paragraphs. Problem: Write a program in C that generates number palindromes using the algorithm below (see 3. on the next page) and allows the user to try this...
0
8420
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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
8842
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
8740
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...
1
6176
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
5642
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
4173
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...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1733
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.