Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Feb 5, 2005, 04:56   #1
celia
SitePoint Enthusiast
 
Join Date: Dec 2004
Location: India
Posts: 96
Problem with checkbox array

hi,
I have got a weird bug . I have a form in which I have lot of checkboxes. Hence I used the grouping convention and named the elements like

<input type="checkbox" name="chk_ticket[]" value="S0001">
<input type="checkbox" name="chk_ticket[]" value="S0002">

and after I post to a script , I expect the $_POST['chk_ticket'] to be an array
with two values S0001 and S0002 if both have been checked.

It does work correctly for me locally (in my machine). And when i execute the
print_R($chk_ticket); also I get the two elements printed .. (only locally).

But in my remote server , the same form and the same code is not working ..
I don't know why?

The remote server has :
PHP Version 4.3.10
Windows NT PARROT 5.0 build 2195
running on Microsoft-IIS/5.0

Does this have anything to do with my script ?

Thanks & Regards,
Celia
celia is offline   Reply With Quote
Old Feb 5, 2005, 05:09   #2
anjanesh
SitePoint Evangelist
 
anjanesh's Avatar
 
Join Date: Jun 2004
Location: Mumbai
Posts: 443
Whats the error Msg ?
anjanesh is offline   Reply With Quote
Old Feb 5, 2005, 05:16   #3
celia
SitePoint Enthusiast
 
Join Date: Dec 2004
Location: India
Posts: 96
Thanks for replying ..

in server,
print_R($chk_ticket) gives me "Array" as output.
SO does print_R($_POST['chk_ticket']);

I am not able to access this variable in my php and if i print count of chk_ticket , i get 1 where as locally this works perfectly .

Regards,
Celia
celia is offline   Reply With Quote
Old Feb 5, 2005, 05:50   #4
celia
SitePoint Enthusiast
 
Join Date: Dec 2004
Location: India
Posts: 96
Bug Fixed.New doubt crops up..

Sorry.Problem was not with the checkbox array as such ..While retrieving all the POST data , I look for magic quotes and if that is not enabled i add slashes and rebuild the array.

if (!get_magic_quotes_gpc())
{
while(list($key,$value)=@each($_POST))
{
$_POST[$key]=addslashes($value); // Problem here
}

}

The above code has caused me the problem when $value happened to be my check box array data.I am still not sure why it caused the problem but I however added a fix to it saying that this if block should execute only if $value is not an array.


if (!get_magic_quotes_gpc())
{
while(list($key,$value)=@each($_POST))
{
if(!is_array($value)
$_POST[$key]=addslashes($value);
}

}



This may not be a good fix.People over here might know it better.But I somehow needed to add a quick fix to it.Please do tell me what is the problem with my former(first) code.

Last edited by celia; Feb 7, 2005 at 00:42. Reason: I thought that this reply of mine was not understood my anyone
celia is offline   Reply With Quote
Old Feb 5, 2005, 07:27   #5
arunkumar
SitePoint Guru
 
arunkumar's Avatar
 
Join Date: Jan 2005
Location: India:Chennai
Posts: 826
Hai celia,
Have you corrected your problem,As my view it will work just try ny giving post_r($_POST) once again at the top of you page and right the next line exit the page.
ArunKumar
arunkumar is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 13:31.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved