[PHP] Arrays and Forms
Hello Everyone, I'm having trouble sending array values through forms. Will the following syntax create a variable called $product['desc'] on the next page? If not, what am I doing wrong here? Note: I tried this but it didn't work! When I tried doing it without using an array, but rather with a regular variable, it sent through just fine and created a variable of the name attribute in the input tag. menu_add.php - form method=post action=menu_list.php input type=text name=product[desc] /form menu_list.php - echo $product['desc']; Result output - no output -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Arrays and Forms
Try: input type=text name=product[] ? foreach ($product as $p) { print $p; } ? On Mon, 20 May 2002 11:05:07 +1200, Navid Y. wrote: Hello Everyone, I'm having trouble sending array values through forms. Will the following syntax create a variable called $product['desc'] on the next page? If not, what am I doing wrong here? Note: I tried this but it didn't work! When I tried doing it without using an array, but rather with a regular variable, it sent through just fine and created a variable of the name attribute in the input tag. menu_add.php - form method=post action=menu_list.php input type=text name=product[desc] /form menu_list.php - echo $product['desc']; Result output - no output -- Jason Morehouse ([EMAIL PROTECTED]) Netconcepts LTD - Auckland, New Zealand Linux: because rebooting is for adding hardware -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Arrays and Forms
On Monday 20 May 2002 07:05, Navid Y. wrote: Hello Everyone, I'm having trouble sending array values through forms. Will the following syntax create a variable called $product['desc'] on the next page? If not, what am I doing wrong here? Note: I tried this but it didn't work! When I tried doing it without using an array, but rather with a regular variable, it sent through just fine and created a variable of the name attribute in the input tag. I don't see anything wrong with the code below. You're saying ... input type=text name=product and echo $product; ... works (on the same server without any other changes)? menu_add.php - form method=post action=menu_list.php input type=text name=product[desc] /form menu_list.php - echo $product['desc']; Result output - no output -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* As far as the laws of mathematics refer to reality, they are not certain, and as far as they are certain, they do not refer to reality. -- Albert Einstein */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Arrays and Forms
Your code looks fine. Are you sure you haven't edited away significant parts of it when posting to the list? Maybe a input name=product somewhere? miguel On Sun, 19 May 2002, Navid Y. wrote: I'm having trouble sending array values through forms. Will the following syntax create a variable called $product['desc'] on the next page? If not, what am I doing wrong here? Note: I tried this but it didn't work! When I tried doing it without using an array, but rather with a regular variable, it sent through just fine and created a variable of the name attribute in the input tag. menu_add.php - form method=post action=menu_list.php input type=text name=product[desc] /form menu_list.php - echo $product['desc']; Result output - no output -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Arrays in forms {?!}
1) The example you have shown should work. Take a look at the foreach controle structure. (Link at bottom of mail.) 2) You cannot assign a value to a checkbox. It can only be set by the checked keyword (ie: input type=checkbox name=foo checked.) 3) The value of a checked checkbox is on. If a checkbox is not checked it will not be passed to you by the clients browser. So if you where wondering why you could not get the value of some of the checkboxes, then that was why. 4) If you don't have to give the user a more thorough description then why not make a multiselect select box instead. Example on a multiselect selectedbox select name=foo[] size=20 multiple option value=bar1desc/option option value=bar2 selecteddesc/option ... /select The above selectbox will display 20 rows in the box and if there is more than 20 selections you will be able to scroll it. You can get more information at: http://www.php.net/manual/en/control-structures.foreach.php http://www.php.net/manual/en/language.variables.external.php _ Marcus Rasmussen - On 24-04-02 at 15:19 Liam MacKenzie wrote: - Hi all, I have a form, with about 40 checkboxes, I want to write a PHP document that processes the submission and displays the values of the checkboxes that were checked. Pretty basic stuff, I've tried a few different things, some work but display Array at the top of the list of values. Snippet of HTML td input type=checkbox name=games[] value=Counter-Strike /td tdCounter-Strike/td td input type=checkbox name=games[] value=Total Annihilation /td tdTotal Annihilation/td /tr /Snippet of HTML Snippet of PHP while ( $element = each( $games ) ) { echo $element[value]; echo br; } /Snippet of PHP I tried this too, it gave the same results as the above... if (is_array($games)) { for ($z=0;$zcount($games);$z++) { echo $games[$z]BR; } } else { echo $games; } I'm missing something real stupid, please help me out Thanks, Liam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Arrays in forms {?!}
Hi all, I have a form, with about 40 checkboxes, I want to write a PHP document that processes the submission and displays the values of the checkboxes that were checked. Pretty basic stuff, I've tried a few different things, some work but display Array at the top of the list of values. Snippet of HTML td input type=checkbox name=games[] value=Counter-Strike /td tdCounter-Strike/td td input type=checkbox name=games[] value=Total Annihilation /td tdTotal Annihilation/td /tr /Snippet of HTML Snippet of PHP while ( $element = each( $games ) ) { echo $element[value]; echo br; } /Snippet of PHP I tried this too, it gave the same results as the above... if (is_array($games)) { for ($z=0;$zcount($games);$z++) { echo $games[$z]BR; } } else { echo $games; } I'm missing something real stupid, please help me out Thanks, Liam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Arrays in forms {?!}
On Wed, 24 Apr 2002, Liam MacKenzie wrote: Snippet of PHP while ( $element = each( $games ) ) { echo $element[value]; echo br; } /Snippet of PHP I tried this too, it gave the same results as the above... if (is_array($games)) { for ($z=0;$zcount($games);$z++) { echo $games[$z]BR; } } else { echo $games; } foreach ($games as $key = $value) echo br$key -- $value; miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] arrays in forms.
Hi, I have a multi-select listbox set up like this: Author (you are able to select more than one.a href=addauthor.phpClick here to add a new author/a)br: select name=author multiple size=5 ?php $result = mysql_query(SELECT AUTHOR_ID, AUTHOR_FNAME, AUTHOR_LNAME FROM AUTHORS;) or die(mysql_error()); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $option = option value= . $row[AUTHOR_ID] . . $row[AUTHOR_FNAME] . . $row[AUTHOR_LNAME] . /option; echo $option; } ? /selectbr I then have a bit of code that parses through and checks which authors they selected, if any. if isset($author) { if is_array($author) { foreach($authors as $key=$value) { $query = INSERT INTO BYLINE(TITLE_ID, AUTHOR_ID) VALUES( . $titleid . , . $value . );; mysql_auery($query) or die(echo mysql_error()); } } else { $query = INSERT INTO BYLINE(TITLE_ID, AUTHOR_ID) VALUES( . $titleid . , . $author . );; mysql_auery($query) or die(echo mysql_error()); } } What I'd like to know is, is this correct, incorrect, redundant, etc? John Meyer [EMAIL PROTECTED] Programmer If we didn't have Microsoft, we'd have to blame ourselves for all of our programs crashing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] arrays in forms.
mysql_auery($query) or die(echo mysql_error()); By the way, I know this line should be mysql_query John Meyer [EMAIL PROTECTED] Programmer If we didn't have Microsoft, we'd have to blame ourselves for all of our programs crashing -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Arrays from forms
Can someone please help me with this code I'm having major problems with arrays. This code is part of a function I'm writing to deal with an array returned from a HTML form of check boxes so if anyone has an example of this sort of thing I'd appreciate a look at it. Anyway Code follows : //Reading from a data base $db = mysql_connect("$DB_Server", "$DB_Login, $DB_Password"); mysql_select_db("$DB_Name",$db); $results = mysql_query("SELECT option_type, code FROM options WHERE code='000' ORDER BY option_type",$db); mysql_fetch_array($results); // From what understand I should have an array some thig like this: // ("Size"="A4" , "Size" = "A3", "Size"="A5", "Colour"="Red", etc..); $types = array_values($results); // OK so now I think I have an array like this: // ("A4" , "A3", "A5", "Red", etc..); while ($type =array_pop($types)){ echo $type."br"; } // Now I'm expecting this list to be printed to be outputted A4 A5 A3 Red etc... I'm figureing that this would be a good way to retreive a listing from the web site arrays and test and insert them one by one. /// The table options option_type || code || option_preferences Size || 000 || A4 Size || 000 || A3 Size || 000 || A5 Colour || 000 || Red Colour || 000 || Blue Colour || 000 || Green
Re: [PHP] Arrays from forms
"Jamie" [EMAIL PROTECTED] wrote: $results = mysql_query("SELECT option_type, code FROM options WHERE code='000' ORDER BY option_type",$db); mysql_fetch_array($results); // From what understand I should have an array some thig like this: // ("Size"="A4" , "Size" = "A3", "Size"="A5", "Colour"="Red", etc..); According to your SQL statement that doesn't appear to be true. According to your SQL statement you'll return two fields: option_type and code. $types = array_values($results); // OK so now I think I have an array like this: // ("A4" , "A3", "A5", "Red", etc..); while ($type =array_pop($types)){ echo $type."br"; } I'd avoid using array_values() and array_pop(). Simply do this: while ( $row = mysql_fetch_array( $result ) ) { $option_type = $row[option_type]; $code = $row[code]; echo "$option_type $codebr"; } Hopefully that'll be enough to get you going. -- Steve Werby COO 24-7 Computer Services, LLC Tel: 804.817.2470 http://www.247computing.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]