JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 14th, 2002, 08:00 AM
alba5 alba5 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 68 alba5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 35 m
Reputation Power: 7
PHP reading Javascript array problem

Hi,

I am populating an array in javascript and then POSTing this array to my PHP script. The problem is my PHP script doesnt seem to be able to find it!

Im treating it as a regular PHP array in my PHP script, am I not taking something into account here?


Hope you can help!

Alba

Reply With Quote
  #2  
Old July 14th, 2002, 08:08 AM
CodE-E CodE-E is offline
<(>_~)>
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 315 CodE-E User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Might this problem be related to register_globals = off?

Try accessing your array with $HTTP_POST_VARS["array"].

Reply With Quote
  #3  
Old July 14th, 2002, 08:20 AM
alba5 alba5 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 68 alba5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 35 m
Reputation Power: 7
Ive changed it from POST to GET.

The url of the recieving PHP script now shows this:

mypage.php?name=fred&array=hey&array=you


where "array" is my array. The number of elements im entering into it are determining the number of times "array=" is shown.

This means it is being passed, how can i get at it, and is it actually an array??

Thanks btw CodeE

Reply With Quote
  #4  
Old July 14th, 2002, 08:40 AM
CodE-E CodE-E is offline
<(>_~)>
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 315 CodE-E User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
mypage.php?name=fred&array=hey&array=you

That isn't going to work.

You are sending $array, which is set to "hey", and then you are sending $array which is set to "you". In the receiving script, $array will probably equal "you", I presume. It won't even be an array - it will just be a string with "you" in it.

If I would be you, I would stick to using POST. Send the array as one variable. Do not try to send all the values in the array sepparately. That kinda destroys the point of an array, no?

Reply With Quote
  #5  
Old July 14th, 2002, 09:26 AM
alba5 alba5 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 68 alba5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 35 m
Reputation Power: 7
I think ive found the problem, How do you pass an array to a PHP script? for example using hidden or another POST method?

Reply With Quote
  #6  
Old July 14th, 2002, 09:29 AM
freud freud is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Germany - Aachen
Posts: 12 freud User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to freud
why don't you make your javascript code name the vars like they should:

array[1] array[2] or anything else. shouldnt be that hard, because normaly you have the counting var so it is easy to index your vars.

if not possible try to change the name from array to array[] this will probably work better.

Reply With Quote
  #7  
Old July 14th, 2002, 09:32 AM
alba5 alba5 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 68 alba5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 35 m
Reputation Power: 7
ive done that I just need to know how to post an array to my PHP script. nothing seems to be working!

Reply With Quote
  #8  
Old July 14th, 2002, 08:06 PM
Yawmark's Avatar
Yawmark Yawmark is online now
Feelin' Groovy
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 7,908 Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level)Yawmark User rank is General 9th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 22 h 21 m 13 sec
Reputation Power: 1592
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
You should be able to access the POST array using the $_POST variables ($_POST['name'] == 'fred', and so on). If you're using an older version of PHP, you may need to use $HTTP_POST_VARS.
Please check PHP.net's description of reserved variables for more detail on what you're looking for.
__________________
Yawmark
class Sig{public static void main(String...args){\u0066or(int
\u0020$:"vÌÈÊ\"¤¾Àʲ¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray()
)System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
+(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}

Reply With Quote
  #9  
Old July 15th, 2002, 12:22 PM
mrGarretson mrGarretson is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 13 mrGarretson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i didnt think you could do such a thing in php. i thought you could only pass variable from input tags, and only pass an array from an select tag? right now, i have a similar problem but *solved* it by putting my javascript array contents into a hidden field, then sending that. if you can pass javascript variables, could someone post an example?

mrGarretson

Reply With Quote
  #10  
Old July 15th, 2002, 12:29 PM
persaltier's Avatar
persaltier persaltier is offline
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: NYC
Posts: 57 persaltier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 19 sec
Reputation Power: 8
Send a message via AIM to persaltier
it doesn't matter if the variable is created using javascript or declared directly in HTML code, every variable that is declared inside a FORM tag and then POSTed to the following page will be available in the $_POST array.

Reply With Quote
  #11  
Old July 16th, 2002, 06:45 AM
jpenn's Avatar
jpenn jpenn is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2002
Location: Washington, DC
Posts: 2,693 jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 41 m 10 sec
Reputation Power: 16
Or he could push the array...

PHP Code:
 $myarray = array();

if (isset(
$var_name_1)) {

   
array_push$myarray$var_name_1 );

}

if (isset(
$var_name_2)) {

   
array_push$myarray$var_name_2 );

}

// and so on for your posting variables // 

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > PHP reading Javascript array problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |