Help with PHP multiple select field

10-23-09, 12:46 AM
|
|
Newbie Coder
|
|
Join Date: Jan 2009
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
|
Help with PHP multiple select field
Hi,
I have a script that updates a multiple select field. I would like it to do the following:
1. check to see if the submitted form has an empty multiple select field and return an error
2. On loading the update page, the previously selected items should be selected in the multiple select field.
Here is what I have so far but I keep on getting the Undefined Index error:
functions.php
update.php
Please help 
Last edited by wirehopper; 10-23-09 at 08:45 AM.
Reason: PHP & HTML tags
|

10-23-09, 07:14 AM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
|
|
Quote:
Originally Posted by paligron
Here is what I have so far but I keep on getting the Undefined Index error
|
The Undefined Index error is telling you that some variable (an array) isn't being declared before use. You can resolve this by declaring all your variables, including arrays, before running any of the code.
|

10-23-09, 08:46 AM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
Add var_dump($_REQUEST); as the first line of your code. That will show you what is being sent from the client.
|

10-23-09, 05:04 PM
|
|
Newbie Coder
|
|
Join Date: Jan 2009
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
the undefined variable is the 'accessories', which is the name of the input field. How do you define it as an array? I have tried to define it normally as an array but the submitted result is always empty.
|

10-23-09, 07:19 PM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
|
|
Quote:
Originally Posted by paligron
the undefined variable is the 'accessories', which is the name of the input field. How do you define it as an array? I have tried to define it normally as an array but the submitted result is always empty.
|
"Undefined index" means the variable you are trying to use doesn't exist (when your variable is not properly set). One way to handle this issue is to check if $_POST['action'] is set before using it. For example:
|
|
The Following User Says Thank You to End User For This Useful Post:
|
|

10-24-09, 12:07 AM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
I changed you r getAccessories() and updateItem() functions.
functions.php
And I modified your update.php code.
__________________
Jerry Broughton
Last edited by job0107; 10-24-09 at 12:47 AM.
|

10-25-09, 02:00 AM
|
|
Newbie Coder
|
|
Join Date: Jan 2009
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
|
thanks job0107
Yup. Thank you guys. Your help is highly appreciated. Job, wrapping ones head around all those if statements, especially for a php newbie like me, is mind tiring. But I understand the concept now. You have also fully answered my original question. I am now on the right track. Thanks a milli.
|

10-25-09, 11:30 PM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
Quote:
Originally Posted by paligron
Yup. Thank you guys. Your help is highly appreciated. Job, wrapping ones head around all those if statements, especially for a php newbie like me, is mind tiring. But I understand the concept now. You have also fully answered my original question. I am now on the right track. Thanks a milli.
|
Understanding the logic flow is 3/4th the battle in creating any program.
Learning the syntax of the language you wish to program in, is the other 1/4.
So, when you have a problem that seems too difficult to figure out, stop and create a flow chart that describes the program flow.
Once you understand what you have to do to make the program work, figuring out the right commands to use becomes much simpler.
__________________
Jerry Broughton
|

10-26-09, 12:18 AM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
I found an error in your updateItem() function and corrected it.
The error was in the quoting of the $id varable.
__________________
Jerry Broughton
|
|
The Following User Says Thank You to job0107 For This Useful Post:
|
|

10-26-09, 01:46 AM
|
|
Newbie Coder
|
|
Join Date: Jan 2009
Posts: 18
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Thanks
It is now working perfectly. I also noticed that the key to the message/error displays lay with the 'in_array' function. Thanks again. This thread can now be closed. Unfortunately, I must claim ignorance as I don't know how to close this thread.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|