473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

retrieving multiple variables in php from ajax using $_POST

5
I cannot seem to retrieve using $_POST in php the variables that I passed using ajax.

i have something like:
Expand|Select|Wrap|Line Numbers
  1. {
  2.         temp1 = "root";
  3.         temp2 = "false";
  4.     var url = "sample.php";
  5.         var arg1 = "arg1="+ temp1;
  6.         var arg2 = "arg2="+ temp2;
  7.     var paramPost = arg1+"&"+arg2;
  8.  
  9.         ...        
  10.          ajax.postIt(paramPost,temp2); 
  11. }
  12.  
  13.  
  14. function postIT(param, temp2) {
  15.         // make a HTTP GET request to the URL asynchronously
  16.                 ...
  17.         request.open("POST",url, true);
  18.             request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  19.             request.setRequestHeader("Content-length",param.length);
  20.             request.setRequestHeader("Connection", "close");
  21.         request.send("param="+param);
  22.  
  23. }
  24.  

in my file.php, i have:
Expand|Select|Wrap|Line Numbers
  1.         ...
  2.  
  3.         if (isset($_POST['param']))
  4.     {
  5.         $args1 = $_POST['arg1'];   //gives out blank 
  6.         $args2 = $_POST['arg2'];   //gives out false value (just right)
  7.  
  8.          }
i also tried:
Expand|Select|Wrap|Line Numbers
  1.         if (isset($_POST['param']))
  2.     {
  3.         $args1 = $_POST['param'];   //gives out "arg1=root" 
  4.         $args2 = $_POST['arg2'];   //gives out false value (just right)
  5.  
  6.          }
am i doing it right? how can i retrieve just the value of $arg1 insteas of the
'name-value' pair?

help! thanks a lot!
Mar 10 '11 #1
1 1955
johny10151981
1,059 1GB
use print_r function to print the $_POST Array

on line 21 of your ajax code
Expand|Select|Wrap|Line Numbers
  1. request.send("param="+param);
skip the variable inside the bracket.

you are actually sending
param=arg1=root&arg2=data(i guess false) so finally what are you sending
value of param is arg1=root and value of arg2 is data, and you are not sending arg1 at all
Mar 10 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Johnny Lin | last post by:
Hi! Is there a way to automate the unbinding of multiple variables? Say I have a list of the names of all variables in the current scope via dir(). Is there a command using del or something...
5
by: Jack | last post by:
Hi, I need to pass multple variables in a link in order to go to a asp page with the two varables. The following are the values of the variables using response.write: <%'Response.Write Mypage...
1
by: Roy | last post by:
I'm assuming this is amazingly simple and I'm just missing the boat. On the html side of an asp.net page I have a datagrid, a "search" button, and 8 text boxes for search criteria. A user enters...
1
by: syntego | last post by:
I am using DB2 V8 fixpack 10 and have the following issue: >From a User Defined Function, I can assign multiple variables in a single statement as follows: -- Get the first update transaction...
7
by: r.z. | last post by:
This is from Visual Studio docs. But is this standard behaviour? I mean, is it ok in every environment: class A { B* my_pointer; A(); ~A(); }
5
by: Heofz | last post by:
Hey all, I've been banging my head against a brick wall on this one for the last 12 hours, and the time has come for me to give up and consult the gurus on this one. The below URL contains a...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
2
by: runway27 | last post by:
i am presently passing the value of a variable to a php file using GET after data has been inserted to the database. ex= $firstname = $_POST; if(!$sqlconnection) { echo "error message"; }
7
by: =?Utf-8?B?TWFyYw==?= | last post by:
Dear all I have a scenario where I have 2 updatepanels on a page, each one containing a weppartzone. the scriptmanager is outside of the updatepanels. when I go to design display mode, i can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.