PHP - How To Pass A Php Value To A Javascript Pop Up
how can i do this ? i have a number of links , when i click one a pop up is displayed, i need to run a php script depending upon which link is clicked.
Or can i run a javascript function once a query string is passed in the url
Please advice.
Edited by chauhanRohit, 12 July 2014 - 04:10 AM. Similar TutorialsI am trying to build a website, whe
1) User logs in (UserA)
2) Inserting a name in the search box and pressing "Search", a list of all users matching that name is shown
3) The user selects a user (UserB) from that list (among several results)
4) By selecting the user (UserB) , a message box appears to insert text
5) The user(UserA) types the message
6) The user(UserA) presses the SUBMIT button and sends the message to the other user(UserB)
The problem i face is how to pass the variables from my PHP script to the JavaScript script. Its easy for me to get the values of input fiedls, select fields or any other DOM element value. But if the value i need to pass to Javascript file to perform an AJAX call isnt inside a DOM element, how do i do it?
For example, for me to determine the user that will send the message (userA), i will need several data. This data, i have them inside the PHP script as variables, but dont know how to pass them to Javascript file.
Getting the data from the URL, or from a hidden input field or any other DOM element, is a solution, but i want to know the way that is safer and better.
To summarize:
[PHP Script with necessary data]-->[pass necessary data from PHP to JavaScript file]-->[perform an AJAX call] --> [return data to PHP Script]
How do i do it?
Thanks in advance.
I work with a large codebase and I have this situation come up fairly often:
the legacy class has large objects such as:
$design->motor->dimensions->a; $design->motor->dimensions->bd; $design->specifications->weight; $design->data->height; //etcWhen I create a new class, that class sometimes operates on the specific data, so say: class MyClass { public function compute($weight, $height, $a) { //stuff } } //and I call this for example as such: (new MyClass())->compute($design->specifications->weight, $design->data->height, $design->motor->dimensions->a);CONS: Potential issue: if design specs change and I need to change things parameters in "compute" function, I need to "re-key" the variables I pass to the function, and adjust things accordinly in MyClass as wel. PROS: only the exact data is being passed, and this data can come from anywhere it is viable, so in effect the function is fairly well separated, I think. Alternative option for me is to pass the entire design object, i.e class MyClass { public function compute(&$design) //can also be done via DI through a setter or constructor. { print $design->specifications->weight; print ($design->data->height + $design->motor->dimensions->a); //stuff } } (new MyClass())->compute($design);PROS: In this case when things change internally in which variables are needed and how things are computed, I only need to change the code in compute function of the class itself. CONS: MyClass now needs to be aware of how $design object is constructed. When it comes to this parameter passing, and Dependency Injection like this in general, does Computer Science advocate a preference on this issue? Do I pass the entire object, or do I pass only the bits and pieces I need? Since there have been some debates about how to safely pass PHP values to JavaScript, I hope I can clarify a few things.
One suggestion that kept recurring was to simply run the value through json_encode() and then inject the result into a script element. The JSON-encoding is supposed to (magically?) prevent cross-site scripting vulnerabilities. And indeed it seemingly works, because naïve attacks like trying to inject a double quote will fail.
Unfortunately, this approach doesn't work at all and is fundamentally wrong for several reasons:
json_encode() was never intended to be a security function. It simply builds a JSON object from a value. And the JSON specification doesn't make any security promises either. So even if the function happens to prevent some attack, this is implementation-specific and may change at any time.
JSON doesn't know anything about HTML entities. The encoder leaves entities like " untouched, not realizing that this represents a double quote which is dangerous in a JavaScript context.
The json_encode() function is not encoding-aware, which makes it extremely fragile and unsuitable for any security purposes. Some of you may know this problem from SQL-escaping: There used to be a function called mysql_escape_string() which was based on a fixed character encoding instead of the actual encoding of the database connection. This quickly turned out to be a very bad idea, because a mismatch could render the function useless (e. g. the infamous GBK vulnerability). So back in 2002(!), the function was abandoned in favor of mysql_real_escape_string(). Well, json_encode() is like the old mysql_escape_string() and suffers from the exact same issues.
Any of those issues can be fatal and enable attackers to perform cross-site scripting, as demonstrated below.
1)
The entire “security” of json_encode() is based on side-effects. For example, the current implementation happens to escape forward slashes. But the JSON standard doesn't mandate this in any way, so this feature could be removed at any time (it can also be disabled at runtime). If it does get disabled, then your application is suddenly wide open to even the most trivial cross-site scripting attacks:
<?php header('Content-Type: text/html; charset=UTF-8'); $input = '</script><script>alert(String.fromCharCode(88, 83, 83));</script><script>'; ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>XSS</title> </head> <body> <script> var x = <?= json_encode($input, JSON_UNESCAPED_SLASHES) ?>; </script> </body> </html>2) In XHTML, a script element works like any other element, so HTML entities like " are replaced with their actual characters (in this case a double quote). But JSON does not recognize HTML entities, so an attacker can use them to bypass json_encode() and inject arbitrary characters: <?php header('Content-Type: application/xhtml+xml; charset=UTF-8'); $input = "";alert('XSS');""; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>XSS</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> </head> <body> <script type="text/javascript"> var x = <?= json_encode($input) ?>; </script> </body> </html>3) json_encode() blindly assumes that the input and the output should always be UTF-8. If you happen to use a different encoding, or if an attacker manages to trigger a specific encoding, you're again left with no protection at all: <?php header('Content-Type: text/html; charset=UTF-7'); $input = '+ACIAOw-alert(+ACI-XSS+ACI)+ADsAIg-'; ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-7"> <title>XSS</title> </head> <body> <script> var x = <?= json_encode($input) ?>; </script> </body> </html>(This particular example only works in Internet Explorer.) I hope this makes it very clear that json_encode() is not a security feature in any way. Relying on it is conceptually wrong and simply a very bad idea. It's generally not recommended to inject code directly into a script element, because any mistake or bug will immediately lead to a cross-site scripting vulnerability. It's also very difficult to do it correctly, because there are special parsing rules and differences between the various flavors of HTML. If you try it, you're asking for trouble. So how should one pass PHP values to JavaScript? By far the most secure and robust approach is to simply use Ajax: Since Ajax cleanly separates the data from the application logic, the value can't just “leak” into a script context. This is essentially like a prepared statement. If you're into micro-optimization and cannot live with the fact that Ajax may need an extra request, there's an alternative approach by the OWASP: You can JSON-encode the data, HTML-escape the result, put the escaped content into a hidden div element and then parse it with JSON.parse(): <?php header('Content-Type: text/html; charset=UTF-8'); $input = 'bar'; ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>XSS</title> <style> .hidden { display: none; } </style> </head> <body> <div id="my-data" class="hidden"> <?php $json_object = json_encode(array( 'foo' => $input, )); // HTML-escape the JSON object echo htmlspecialchars($json_object, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, 'UTF-8'); ?> </div> <script> var data = JSON.parse(document.getElementById('my-data').innerHTML); alert('The following value has been safely passed to JavaScript: ' + data.foo); </script> </body> </html> Code: [Select] <form action='test.php' method='post'> <input id="Username" type="hidden" name="date2" /> <input type="submit" name="action" value="Submit"></form> Hi I want to pass a Username javascript variable to test.php as hidden, anyone can help? When code this Code: [Select] <input id="Username" type="input" name="date2" />Data can pass to test.php When code this Code: [Select] <input id="Username" type="hidden" name="date2" />Data fail to pass over I'm trying to get a simple table to display and am not sure how to make it happen. Table will have just 2 columns. A TIME and an EVENT. What I want to have happen is for the first row to show the TIME and next to that, the EVENT. If a TIME has more than one event going I want the next row to show an empty first cell and then the second event below the first. If I set up the loop the only way I know how (so far) it would also output the TIME value again and again as many times as there were events for that same time. For example what I don't want is: 9:15 Sunday School 9:15 Nursery Available What I do want is: 9:15 Sunday School Nursery Available Thanks. Code: [Select] $col = 0; if ($num_products_count > 0) { while (!$specials_index->EOF) { $list_box_contents[$row][$col] = array('params' =>'<a href="#">' .zen_image(..). '</a>'), $col ++; } } now i want to pass some values<img src="1.jpg">,<img src="1.jpg">,<img src="2.jpg">,<img src="3.jpg">,<img src="4.jpg">,<img src="5.jpg"> to zen_image(..). how should i do? namely, if there are five loops.i want to change zen_image(..) output result to (<img src="1.jpg">,<img src="1.jpg">,<img src="2.jpg">,<img src="3.jpg">,<img src="4.jpg">,<img src="5.jpg">) Hello there,
I have 2 questions:
1) Look he http://www.hellastra...ooking/taxi.php
I have a form and i want to pass values from URL to fields.
So, for example to pass a value to Prefered driver ID field you write this:
http://www.hellastra...?drivercode-123 and the value 123 is passed to that field. I did this with this code:
<?php $sDriverCode = $_REQUEST['drivercode']; ?> <input style="width:100px;" name="drivercode" id="drivercode" value="<?=$sDriverCode?>" data-mini="true" />At the same form i have some radio-type fields. Its the one you see at Type of Vehicle (Standard, Premium etc). When i try to do the same, i cannot get this to work. What i am trying to do is this: Hello
I'm using a form to collect user data (is a Cognito form) it is displayed on vacation rental properties pages, so it collects user´s email, in date, out date, etc. in the cognito form I have one text hidden field called REF, I wonder how to do in order to use the same form and be able to identify where the info comes from. I thougt that if I could put the page url into the REF variable, the problem would be solved, but I'm not sure if that is possible and how to do it. It is? If not: is it possible to handle that ? I have researched all over forums from past day. Not getting correct solution. I have 2 textboxes and a button. First box is to enter value and i will click button, i need to get the value.
Here is the code, that works without input box 1
In this code i want to modify my web address, at the end after ky= i want add my first textbox value, then click event and output in second textbox, let me know where i messed.
<script type="text/javascript"> function Assign() { <?php $html = file_get_contents("http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=79401:006:0812" ); preg_match_all('(<li.*?>.*?</li>)', $html, $matches); $one=$matches[0][0]; ?> document.getElementById("OutputField").value = "<?=$one?>"; } </script> <input id="InputField" type="text" style="width:200px"/> <input type="submit" value="Assign Value" onclick="Assign()"/> <input id="OutputField" type="text" style="width:200px"/> Hi guys, I have got a problem with the if variable statements. When I insert the text of the image location, the name of the strings and when I did not insert the username, all I get this: Code: [Select] image, strings or username are missing Username or password are missing. It should not display with the "Username or password are missing.", only the "image, strings or username are missing". The area of the code i am working on: if($image == '' && $strings == '' && $username == '') { $errmsg_arr[] = 'image, strings or username are missing'; $errflag = true; } elseif($username == '' && $password == ''){ $errmsg_arr[] = 'Username or password are missing.'; $errflag = true; } <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $image = clean($_GET['image']); $strings = clean($_GET['strings']); $username = clean($_GET['user']); $pass = clean($_GET['pass']); $delete = clean($_GET['delete']); if($image == '' && $strings == '' && $username == '') { $errmsg_arr[] = 'image, strings or username are missing'; $errflag = true; } elseif($username == '' && $password == ''){ $errmsg_arr[] = 'Username or password are missing.'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['image'])) { $insert[] = 'image = \'' . clean($_GET['image']) . '\''; } if(isset($_GET['strings'])) { $insert[] = 'strings = \'' . clean($_GET['strings']) . '\''; } if(isset($_GET['user'])) { $insert[] = 'username = \'' . clean($_GET['user']) .'\''; } if(isset($_GET['pass'])) { $insert[] = 'pass = \'' . clean($_GET['pass']) . '\''; } if(isset($_GET['delete'])) { $insert[] = 'delete = \'' . clean($_GET['delete']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if(isset($image) && ($strings) && ($username)) { echo "test"; } elseif($username && $delete == 'all') { if ($delete != NULL) { mysql_query("DELETE FROM user_list WHERE username='$username'"); $deleted = mysql_affected_rows(); if($deleted > 0) { echo("The data are now deleted"); } else { echo("The user's data is empty"); } }else{ echo("failed"); } mysql_close($link); } } } ?> Do anyone know how i can get pass on those methods if I enter the images, the name of the strings and the username or the or the username with the password? Hi guys, I need your help, I have got a problem with the if statement. When I don't insert the pass function in the url like this: Code: [Select] http://www.mysite.com/myscript.php?image=myimagelocation&strings=mystrings&user=test I will get this on my php page: Code: [Select] PASSWORD are missing Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $image = clean($_GET['image']); $strings = clean($_GET['strings']); $username = clean($_GET['user']); $pass = clean($_GET['pass']); if($username == '' && $pass) { $errmsg_arr[] = 'username are missing'; $errflag = true; }elseif($username && $pass =='') { $errmsg_arr[] = 'PASSWORD are missing'; $errflag = true; } if($username == '' && $pass == '') { $errmsg_arr[] = 'username or password missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['image'])) { $insert[] = 'image = \'' . clean($_GET['image']) . '\''; } if(isset($_GET['strings'])) { $insert[] = 'strings = \'' . clean($_GET['strings']) . '\''; } if(isset($_GET['user'])) { $insert[] = 'user = \'' . clean($_GET['user']) .'\''; } if(isset($_GET['pass'])) { $insert[] = 'pass = \'' . clean($_GET['pass']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); $required_fields = array('image', 'strings', 'user'); if($image && $strings && $username) { echo "working 1"; } elseif($username && $pass) { echo "working 2"; } } } ?> Do anyone know how to fix this? this is my nav menu code Code: [Select] <ul> <li><a href='fountains_page.php?id=all'>all fountains</a></li> <li><a href='fountains_page.php?id=garden'>garden fountains</a></li> <li><a href='fountains_page.php?id=wall'>wall fountains</a></li> </ul> this is my script Code: [Select] require('dbconnect.php'); $id = $_GET['id']; if($id = all){ $records = "SELECT * FROM (fountains)"; }else{ if ($id = garden){ $records = "SELECT * FROM (fountains) WHERE wall='no'"; }else{ if($id = wall){ $records = "SELECT * FROM (fountains) WHERE wall='yes'"; } } } $query_records = mysql_query($records); $num_records = mysql_num_rows($query_records); if ($num_records == 0) { echo "The menu is closed for now."; } else{ $i=1; } echo 'We have'.' '.$num_records.' '.'fountains for your consideration<br />Please visit our store to view hundreds of styles.<br />'; echo $id; $errors = array(); // initialize error array Here is the link http://www.mywebsitepaid.com/stonemans/fountains_page.php I can't get the 'id' to pass. What am I doing wrong? I did another site fine, but here I messed something up. hello how do i pass a value from 1 function to another i want to use this part Code: [Select] //send the list order to the navigation or list page $PHL = PhLists::by_listNo($PHGlno); foreach ($PHL as $PHLs){ $PHLlno = $PHLs->phList_No; $PHLorb = $PHLs->orderBy; $PHLord = $PHLs->orderDir; } from this very long function. Code: [Select] function include_placeHolders($position, $phNo, $pageID){ $langBS = basicSettings::find_by_id(1); $langID = $langBS->language_id; //FIND PLACEHOLDER BY ID $PH = Placeholders::find_by_pageID($pageID); foreach ($PH as $PHs){ $PHpos = $PHs->position; $PHnum = $PHs->phNumber; $PHgNo = $PHs->phGroup_No; $PHgFx = $PHs->PHGfx_id; $PHgThm = $PHs->PHGtheme_id; if($phNo == $PHnum && $position == $PHpos){ //FIND ELEMENT THEMES echo '<style type="text/css" media="screen">'; include(PAGES.DS."phGroups".DS."theme{$PHgThm}".DS."css".DS."styles.css"); echo '</style>'; echo'<div id="PHgroup">'; //FIND GROUPS BY phGroupNo $PHGodr = PhGroups::find_order($PHgNo); foreach ($PHGodr as $PHGodrs){ $PHGob = $PHGodrs->orderBy; $PHGod = $PHGodrs->orderDir; } //FIND PHGROUPS BY BY GROUPno & ORDER $PHG = PhGroups::find_by_order($PHgNo, $PHGob, $PHGod); foreach ($PHG as $PHGs){ $PHGid = $PHGs->id; $PHGname = $PHGs->name; $PHGgno = $PHGs->phGroup_No; $PHGlno = $PHGs->list_No; $PHGce = $PHGs->contElements_id; $PHGpl = $PHGs->pageLink_id; $extLink = $PHGs->extLink_id; $PHfx = $PHGs->PHfx_id; $PHthm = $PHGs->PHtheme_id; //send the list order to the navigation or list page $PHL = PhLists::by_listNo($PHGlno); foreach ($PHL as $PHLs){ $PHLlno = $PHLs->phList_No; $PHLorb = $PHLs->orderBy; $PHLord = $PHLs->orderDir; } //FIND EXTERNAL LINK $PHGeL = ExtLinks::find_link($extLink); foreach($PHGeL as $PHGeLs){ $PHGurl = $PHGeLs->url; $PHGtarget = $PHGeLs->target; } //FIND ELEMENTS $CE = ContElements::find_by_phg($PHGce); foreach ($CE as $CEs){ $CEeName = $CEs->name; $CEetype = $CEs->elementTypes_id; $CEefx = $CEs->elFx_id; $CEethm = $CEs->elTheme_id; //FIND ELEMENT TYPE NAME $CEt = ElementsTypes::find_Etype($CEetype); foreach ($CEt as $CEts){ $CEtName = $CEts->name; //FIND PLACEHOLDER THEMES echo '<style type="text/css" media="screen">'; include(PAGES.DS."placeHolders".DS."theme{$PHthm}".DS."css".DS."styles.css"); echo '</style>'; //FIND ELEMENT THEMES echo '<style type="text/css" media="screen">'; include(ELEMENTS.DS."{$CEtName}".DS."themes".DS."theme{$CEethm}".DS."css".DS."styles.css"); echo '</style>'; //FIND INTERNAL OR EXTERNAL LINK $pageLNK = (empty($PHGpl)) ? '' : '<a href="index.php?pageID='.$PHGpl.'">'; $extLNK = (empty($extLink)) ? '' : '<a href="'.$PHGurl.'" target="'.$PHGtarget.'">'; $ENDpageLNK = (empty($PHGpl)) ? '' : '</a>'; $ENDextLNK = (empty($extLink)) ? '' : '</a>'; echo $pageLNK; echo $extLNK; echo'<div id="ph"> <div id="PHelement">'; include(ELEMENTS.DS."{$CEtName}".DS."{$CEeName}.php"); echo'</div></div>'; echo $ENDpageLNK; echo $ENDextLNK; } } } echo'</div>'; } } } i want the next long function to use these values Quote $PHLlno = $PHLs->phList_No; $PHLorb = $PHLs->orderBy; $PHLord = $PHLs->orderDir; this is where i want to use them in the next function Quote $nH = PhLists::navOrder($PHLlno, $PHLorb, $PHLord); Code: [Select] function nav(&$navLink){ $nH = PhLists::navOrder($PHLlno, $PHLorb, $PHLord); foreach ($nH as $nHs){ $nav_typ = $nHs->type; $nav_lvl = $nHs->levels; $nav_pLnk = $nHs->pageLink_id; $nav_eLnk = $nHs->extLink_id; $nav_tType = $nHs->titleType; $nav_ctBid = $nHs->custTxtBridge_id; //INTERNAL LINKS if($nav_typ == "Internal"){ //USE SET TITLE if($nav_tType == "SetTitle"){ $navPage = Pages::findNav($nav_pLnk); foreach ($navPage as $navPages){ $NPbid = $navPages->PCbridge_id; } $STBhead = PCbridge::find_setTitle($NPbid, $langID); foreach ($STBhead as $STBheads){ $text = $STBheads->pageContent_id; } $navText = PageContent::find_text($text); foreach ($navText as $navTexts){ $navLink = $navTexts->title; } //USE CUSTOM TITLE }else if($nav_tType == "Custom"){ $CTBhead = PCbridge::find_customTitle($nav_ctBid, $langID); foreach ($CTBhead as $CTBheads){ $text = $CTBheads->pageContent_id; } $navText = PageContent::find_text($text); foreach ($navText as $navTexts){ $navLink = $navTexts->title; } } } //EXTERNAL LINKS if($nav_typ == "External"){ //USE SET TITLE if($nav_tType == "SetTitle"){ $navExt = ExtLinks::findNav($nav_eLnk); foreach ($navExt as $navExts){ $navLink = $navExts->name; $PHGurl = $navExts->url; $PHGtarget = $navExts->target; } //USE CUSTOM TITLE }else if($nav_tType == "Custom"){ $navExt = ExtLinks::findNav($nav_eLnk); foreach ($navExt as $navExts){ $PHGurl = $navExts->url; $PHGtarget = $navExts->target; } $CTBhead = PCbridge::find_customTitle($nav_ctBid, $langID); foreach ($CTBhead as $CTBheads){ $text = $CTBheads->pageContent_id; } $navText = PageContent::find_text($text); foreach ($navText as $navTexts){ $navLink = $navTexts->title; } } } //NO LINK if($nav_typ == "Non"){ //USE CUSTOM TITLE if($nav_tType == "Custom"){ $CTBhead = PCbridge::find_customTitle($nav_ctBid, $langID); foreach ($CTBhead as $CTBheads){ $text = $CTBheads->pageContent_id; } $navText = PageContent::find_text($text); foreach ($navText as $navTexts){ $navLink = $navTexts->title; } } } } } thanks Cant seem to figure this one out for a chained script. In the code below I need to take the value of $drop_var from function drop_1() and send it to function drop_2() So I can add it to the Where clause to limit the results of the third box a little more. But I cannot get the value to pass to the function. Any help appreciated. func.php <?php //************************************** // Page load dropdown results // //************************************** function getTierOne() { $result = mysql_query("SELECT DISTINCT branch FROM rank") or die(mysql_error()); while($tier = mysql_fetch_array( $result )) { echo '<option value="'.$tier['branch'].'">'.$tier['branch'].'</option>'; } } //************************************** // First selection results // //************************************** if($_GET['func'] == "drop_1" && isset($_GET['func'])) { drop_1($_GET['drop_var']); } function drop_1($drop_var) { include_once('db.php'); $result = mysql_query("SELECT DISTINCT type FROM rank WHERE branch='$drop_var'") or die(mysql_error()); echo '<select name="drop_2" id="drop_2"> <option value=" " disabled="disabled" selected="selected">Choose one</option>'; while($drop_2 = mysql_fetch_array( $result )) { echo '<option value="'.$drop_2['type'].'">'.$drop_2['type'].'</option>'; } echo '</select>'; echo "<script type=\"text/javascript\"> $('#wait_2').hide(); $('#drop_2').change(function(){ $('#wait_2').show(); $('#result_2').hide(); $.get(\"func.php\", { func: \"drop_2\", drop_var2: $('#drop_2').val() }, function(response){ $('#result_2').fadeOut(); setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400); }); return false; }); </script>"; } //************************************** // Second selection results // //************************************** if($_GET['func'] == "drop_2" && isset($_GET['func'])) { drop_2($_GET['drop_var2']); } function drop_2($drop_var2) { echo "<br>($drop_var)<br>"; include_once('db.php'); $result = mysql_query("SELECT * FROM rank WHERE type='$drop_var2'") or die(mysql_error()); echo '<select name="drop_3" id="drop_3"> <option value=" " disabled="disabled" selected="selected">Choose one</option>'; while($drop_3 = mysql_fetch_array( $result )) { echo '<option value="'.$drop_3['grade'].'">'.$drop_3['grade'].'</option>'; } echo '</select>'; echo '<input type="submit" name="submit" value="Submit" />'; } ?> index.php <?php include('db.php'); include('func.php'); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Chained Select Boxes using PHP, MySQL and jQuery</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#wait_1').hide(); $('#drop_1').change(function(){ $('#wait_1').show(); $('#result_1').hide(); $.get("func.php", { func: "drop_1", drop_var: $('#drop_1').val() }, function(response){ $('#result_1').fadeOut(); setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { $('#wait_1').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } function finishAjax_tier_three(id, response) { $('#wait_2').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } </script> </head> <body> <p> <form action="" method="post"> <select name="drop_1" id="drop_1"> <option value="" selected="selected" disabled="disabled">Select a Category</option> <?php getTierOne(); ?> </select> <span id="wait_1" style="display: none;"> <img alt="Please Wait" src="ajax-loader.gif"/> </span> <span id="result_1" style="display: none;"></span> <span id="wait_2" style="display: none;"> <img alt="Please Wait" src="ajax-loader.gif"/> </span> <span id="result_2" style="display: none;"></span> </form> </p> <p> <?php if(isset($_POST['submit'])){ $drop = $_POST['drop_1']; $drop_2 = $_POST['drop_2']; $drop_3 = $_POST['drop_3']; echo "You selected a "; echo $drop_3." ".$drop." ".$drop_2; } ?> </body> </html> so I need some help passing these variable from this page to final.php. how do I pass these arrays? I know if it were singled....not arrayed, I could use hidden fields in a form and echo them out....but these are multiples....not singled. The form way is prefered.....but it doesn't have to be. I just need these passed to the page where I am going to process them. I am not good at working with arrays. Thanks in advance Code: [Select] <?php include_once("connect.php"); session_start(); foreach($_POST["product"] AS $key => $val) { $product = $val; $month = $_POST['month'][$key]; $day = $_POST['day'][$key]; $year = $_POST['year'][$key]; $date = $_POST['date'][$key]; $price = $_POST['price'][$key]; $qty = $_POST['qty'][$key]; $id = $_POST['id'][$key]; $total = $_POST['total'][$key]; $academy = $_POST['academy'][$key]; $priceunit = $price * $qty; } ?> I'd like to pass a value from a URL to an iframe. This would look as follows: URL: http://www.mysite.com?www.mysite2.com The value (www.mysite2.com) will be an actual web address which should then be inserted into an iframe on www.mysite.com via php. Since I know little to no php, I don't know how the URL has to be structured and what php coding I need to use to include the web address in the iframe. Any suggestions are highly appreciated Trying to pass VARS $URL1 and $type to header location.Heres the code. Code: [Select] $URL1 = $_POST['url']; $type = $_POST['type_request']; session_start(); $string = strtoupper($_SESSION['string']); $userstring = strtoupper($_POST['userstring']); session_destroy(); if (($string == $userstring) && (strlen($string) > 4)) { header("Location: $success"); exit(); The VARS come from a FORM and then go to this script for checkind data. I need to have them continue to the next page. Hi ! I need to pass a lot of variables using GET, and many of them are related, so I was thinking in two options: 1) Pass them as array: Code: [Select] example.php?categories[]=cat1&categories[]=cat2 2) Pass them in a single parameter, and split it in PHP (a custom and simpler serializer) Code: [Select] example.php?categories=cat1|cat2 What do you think is better? (or maybe there is a 3rd option...) The second method seems more readable and short, the first easier to construct and maybe faster because we don't need to "unserialize". But I'm looking for better reasons. I'm thinking in a possible advantage of the first method over the second for SEO, because if Google is smart enough to understand that categories[] are all the same, then can understand that: Code: [Select] example.php?categories[]=cat1&categories[]=cat2is equal to: Code: [Select] example.php?categories[]=cat2&categories[]=cat1I think that is more difficult for Google to understand that with: Code: [Select] example.php?categories=cat1|cat2and Code: [Select] example.php?categories=cat2|cat1 Regards!! Enrique. i hav this url n whenever i click on this url i get som mssg send on my mobile i hav a form whose code is Code: [Select] <form action="formprocess.php method="post"> telephone<input type="text name="telephone> <input type="submit" name="submit"> </form> i want to send telephone as parameter to this url so whenever user enters his telephone he gets d mssg after clicking on submit.....but i hav no idea how to do tht...help me somone plssssssss http://www.abc.in/smsapi/sendsms.php?sendto=9987234123&msg=your |