techker Posted February 28, 2009 Share Posted February 28, 2009 hey guys i have this list box that when you select what categorie you want it refresh's the page to get the infor from a databse. now it works fine but somethims when you play arraound to mutch with the select box it does notretain the user id? <?php session_start(); if(!session_is_registered(myusername)){ header("location:login.php"); } $_id=$_POST['_id']; $client_id=$_GET['client_id']; require "config2.php"; $connection = mysql_connect($dbhost, $dbusername, $dbpass); $SelectedDB = mysql_select_db($dbname); ?> <!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>GRAPH</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='ex9.php?_id=<? print"$client_id"?>&cat=' + val ; } function reload3(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; var val2=form.subcat.options[form.subcat.options.selectedIndex].value; self.location='ex9.php?_id=<? print"$client_id"?>&cat=' + val + '&cat3=' + val2 ; } </script> <script type="text/javascript"> function swapImage(){ var image = document.getElementById("imageToSwap"); var dropd = document.getElementById("subcat"); image.src = dropd.value; }; </script> </head> <body> <img id="imageToSwap" src="http://www.webworkout.info/Account/images/gymgraphb.jpg" /> <? $quer2=mysql_query("SELECT DISTINCT category FROM category order by category"); $cat=$HTTP_GET_VARS['cat']; // This line is added to take care if your global variable is off $c_id=$HTTP_GET_VARS['_id']; echo "<form method=post name=f1 action='dd3ck.php?client_id=$c_id'>"; ////////// Starting of first drop downlist ///////// echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['category']==@$cat){echo "<option selected value='$noticia2[category]'>$noticia2[category]</option>"."<BR>";} else{echo "<option value='$noticia2[category]'>$noticia2[category]</option>";} } echo "</select>"; if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT DISTINCT pic,id FROM $cat" ); }else{$quer=mysql_query("SELECT DISTINCT pic,id FROM $cat "); } echo "<select name='subcat'onChange='swapImage()' ><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { if($noticia['pic']==@$cat3){echo "<option selected value='$noticia[pic]'>$noticia[pic]</option>"."<BR>";} else{echo "<option value=/Account/PICS/$cat/$noticia[pic]>$noticia[pic]</option>";} } echo "</select>"; echo "<input type=hidden name='location' value='1'>"; echo "<input type=submit value='Submit'></form>"; ?> <label><br /> </label> <p> <p> </p> </body> </html> this part makes it always post the info var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='ex9.php?_id=<? print"$client_id"?>&cat=' + val ; see any mistakes in the script??? Quote Link to comment https://forums.phpfreaks.com/topic/147296-select-refresh/ Share on other sites More sharing options...
MadTechie Posted February 28, 2009 Share Posted February 28, 2009 see any mistakes in the script??? Well yes !! $_id=$_POST['_id']; // is never used (as $_POST['_id'] never set) also shouldn't all the '_id'= be 'client_id' then remove $c_id=$HTTP_GET_VARS['_id']; and replace '$c_id' 's with $client_id $HTTP_GET_VARS was deprecated, so use $_GET instead your echo'ed $noticia2[category]'s should be replaced with {$noticia2['category']}, same with $noticia[pic] to {$noticia['pic']} theirs a quick overview Quote Link to comment https://forums.phpfreaks.com/topic/147296-select-refresh/#findComment-773223 Share on other sites More sharing options...
techker Posted February 28, 2009 Author Share Posted February 28, 2009 interesting! $HTTP_GET_VARS was deprecated, so use $_GET instead cool understood your echo'ed $noticia2[category]'s should be replaced with {$noticia2['category']}, same with $noticia[pic] to {$noticia['pic']} why use { and why is it working? Quote Link to comment https://forums.phpfreaks.com/topic/147296-select-refresh/#findComment-773229 Share on other sites More sharing options...
MadTechie Posted February 28, 2009 Share Posted February 28, 2009 first $noticia2[category] is wrong unless you have category as a constant.. if PHP doesn't find a category constant it will use "category" (a string) instead however its good pratice to use a string to start with so $noticia2['category'] reason you add the {} is because If a dollar sign ($) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. So you need to enclose the variable name in curly braces to explicitly specify the end of the name. more info See "Variable parsing" section in string types paret of the manual you could concatanate it instead! ie echo "<option value='".$noticia2['category']."'>".$noticia2['category']."</option>"; Why is it working.. Well php is smart and is assuming what you mean!! Quote Link to comment https://forums.phpfreaks.com/topic/147296-select-refresh/#findComment-773238 Share on other sites More sharing options...
techker Posted March 1, 2009 Author Share Posted March 1, 2009 thx for the info.would there be any reason why it sometimes when you selectect multiple times or go thrue the categories it gets confused and does not show the client id anymore it likes looses it? and is it possible to multiply this script on one page?cause when i try it the refresh does all the copies.. Quote Link to comment https://forums.phpfreaks.com/topic/147296-select-refresh/#findComment-773748 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.