/    Sign up×
Community /Pin to ProfileBookmark

This simply does not make sense to me!

Why is it that the following 2 examples work, but the last doesn’t?

Example 1: An onchange event from a drop down list is passing the correct string to the function’s selectedText argument so the value of text1 field is being set correctly on the onchange event.
<SCRIPT LANGUAGE=’JavaScript’ type=’text/javascript’>
<!– //
function getMembers(selectedText) {
members = new Array();
<?php
$membersName = selectedText;
print(“members[0] = $membersName;n”);
?>
Form1.text1.value = members[0];

// –>
}
</SCRIPT>

Example 2: Here, I’m ignoring the selectedText argument and hard coding the PHP variable to the text that would be passed to the function. Query works fine, and the correct value is displayed in text1 on the onchange event of the dropdown list. (Not shown here)
<SCRIPT LANGUAGE=’JavaScript’ type=’text/javascript’>
<!– //
function getMembers(selectedText) {

members = new Array();
<?php
$membersName = “Pine Ridge Fellowship Church”;
$query2 = “SELECT groups_id FROM groups WHERE groups.groups_name = “” . $membersName . “””;
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_array($result2)) {
$members[] = $row2[‘groups_id’];
}
print(“members[0] = $membersName;n”);
?>
Form1.text1.value = members[0];

// –>
}
</SCRIPT>

Example 3. This is what doesn’t make sence. Combine the 2 above to get this and it does not set text1 value properly.
<SCRIPT LANGUAGE=’JavaScript’ type=’text/javascript’>
<!– //
function getMembers(selectedText) {

members = new Array();
<?php
$membersName = selectedText;
$query2 = “SELECT groups_id FROM groups WHERE groups.groups_name = “” . $membersName . “””;
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_array($result2)) {
$members[] = $row2[‘groups_id’];
}
print(“members[0] = $row2[0];n”);
?>
Form1.text1.value = members[0];

// –>
}
</SCRIPT>

The 1st example proves that I can pass a JS function argument’s value to a PHP variable.

The 2nd example proves I can use a PHP variable in a SQL query. (of course)

The last example says I can’t use a PHP variable that received it’s value from the JS function argument in a SQL query although combining the first 2 examples would logically say I could. Does this make sense to anyone? So what am I doing wrong here?!

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @jackand7 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.9,
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,
)...