/    Sign up×
Community /Pin to ProfileBookmark

Problem Passing Parameters to PHP

Running an Ajax script and the number of parameters i’m passing is dynamic. My parameter string is generated and sent to the PHP via the following function:

[CODE]function save(numStd){

//Find Selected Class
var all = document.all ? document.all :
document.getElementsByTagName(‘*’);
var elements = new Array();
for (var e = 0; e < all.length; e++)
if (all[e].className == ‘active’)
var currentClass=all[e].id;

var sendParams=escape(numStd)+”&param1=”+escape(currentClass);
var paramCounter=2

for(var i = 1; i <= numStd; i++){
window[‘lNameSave’+i] = document.getElementById(“LastName”+i).value;
window[‘fNameSave’+i] = document.getElementById(“FirstName”+i).value;
window[‘ageSave’+i] = document.getElementById(“Age”+i).value;

sendParams =sendParams+”&param”+paramCounter+”='”+escape(window[‘lNameSave’+i])+”‘”;
paramCounter++;
sendParams =sendParams+”&param”+paramCounter+”='”+escape(window[‘fNameSave’+i])+”‘”;
paramCounter++;
sendParams=sendParams+”&param”+paramCounter+”=”+escape(window[‘ageSave’+i]);
paramCounter++;

}
var urlNewStd = “/phpscripts/saveNewStd.php?param=”;
http.open(“GET”, urlNewStd + sendParams, true);
document.getElementById(“studentresult”).innerHTML=”<img src=’/images/ajax-loader.gif’ style=’margin:50px 0 0 110px;’/>”;
http.onreadystatechange = handleHttpResponseNewStd;
http.send(null);
}[/CODE]

if I input two records to send as parameters this is an example of what urlNewStd + sendParams looks like:

[CODE]/phpscripts/saveNewStd.php?param=2&param1=4A&param2=’Williams’&param3=’Robin’&param4=55&param5=’Moore’&param6=’Demi’&param7=45[/CODE]

once it is in the PHP I can only access the first parameter which in the example would be “2”

any ideas?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@toicontienDec 10.2008 — You don't need single quotes wrapping the parameter values in the query string.

Also, you should be using encodeURIComponent() instead of escape()
Copy linkTweet thisAlerts:
@cfgcjmauthorDec 10.2008 — still nothing...
Copy linkTweet thisAlerts:
@toicontienDec 10.2008 — Are you trying to access all the params by using $_GET['param'], as if $_GET['param'] is an array? If so, you need to change all the param names from "param#" to "param[]".
Copy linkTweet thisAlerts:
@cfgcjmauthorDec 11.2008 — my php code is tying to get the variables via like this:

[code=php]$variable= urldecode($_GET['param1']);[/code]
×

Success!

Help @cfgcjm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...