PHP - Using Php To Sleect Value From Drop Down Menu Not Working
Can anyone suggest why the drop down is not selecting the users selected option :S
Code: [Select] <select name="level_id"> <option value="" selected="selected">- Please Select -</option> <?php mysql_data_seek($rsl,0); if (mysql_num_rows($rsl)>0): while ($rowl = mysql_fetch_assoc($rsl)):?> <option value="<?=$row1['id']?>" <?if ($row1['id']==$rowq['level_id']) echo 'selected="selected"';?>><?=stripslashes($rowl['title'])?></option> <?php endwhile; endif; ?> </select> Similar Tutorialstrying to get a drop-down menu (in a form) to work that needs to get populated from a table table called : CarCategory in this table are 2 columns called CarCategoryID (unique number from 1-18) CarCategoryDesc (actual name of category.. e.g. 'convertible') link : http://98.131.37.90/postPart.php I'm a total novice.. and can't figure out why the first is not working and the second (country) is working code : <!--NOT WORKING ... why not ?? should show drop down menu--> <label> <div align="center"> <select name="carcategory" id="CarCategory" class="validate[required]" style="width: 200px;"> <option value="">Select Car Category from list...</option> <?php while($obj_queryCarCategory = mysql_fetch_object($result_queryCarCategory)) { ?> <option value="<?php echo $obj_queryCarCategory->CarCategoryID;?>" <?php if($obj_queryCarCategory->CarCategoryID == $UserCountry) { echo 'selected="selected"'; } ?> > <?php echo $obj_queryCarCategory->CarCategoryDesc;?></option> <?php } ?> </select> </div> </label> <!-- working ! --> <label> <div align="center"> <select name="country" id="Country" class="validate[required]" style="width: 200px;"> <option value="">Select...</option> <?php while($obj_queryCountry = mysql_fetch_object($result_queryCountry)) { ?> <option value="<?php echo $obj_queryCountry->CountryID;?>" <?php if($obj_queryCountry->CountryID == $UserCountry) { echo 'selected="selected"'; } ?> > <?php echo $obj_queryCountry->CountryName;?></option> <?php } ?> </select> </div> </label> Hi, i wonder whether someone may be able to help me please. I am using a combination of PHP and AJAX to create two drop down menus on a HTML form. The data is being pulled from a mySQL database with the options available in the second drop down dependent on the value selected in the first. The initial drop down menu called 'detectors' and the behaviours for the second drop down menu, 'searchheads' are created with the following AJAX code: Code: [Select] Function AjaxFunction(detectorid) { var httpxml; try { // Firefox, Opera 8.0+, Safari httpxml=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { httpxml=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpxml=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } function stateck() { if(httpxml.readyState==4) { var myarray=eval(httpxml.responseText); // Before adding new we must remove previously loaded elements for(j=document.addfindstolocation.searchheads.options.length-1;j>=0;j--) { document.addfindstolocation.searchheads.remove(j); } for (i=0;i<myarray.length;i++) { var optn = document.createElement("OPTION"); optn.text = myarray[i]; optn.value = myarray[i]; document.addfindstolocation.searchheads.options.add(optn); } } } var url="searchheaddetails.php"; url=url+"?detectorid="+detectorid; url=url+"&sid="+Math.random(); httpxml.onreadystatechange=stateck; httpxml.open("GET",url,true); httpxml.send(null); } The following code is the file 'searchheaddetails.php' (as highlighted above) which populates the second drop down menu. Code: [Select] <? $detectorid=$_GET['detectorid']; require "config.php"; $q=mysql_query("SELECT * FROM searchheads WHERE detectorid='$detectorid' ORDER BY 'searchheadname' ASC"); echo mysql_error(); $myarray=array(); $str=""; while($nt=mysql_fetch_array($q)){ $str=$str . "\"$nt[searchheadname]\","; } $str=substr($str,0,(strLen($str)-1)); // Removing the last char , from the string echo "new Array($str)"; ?> And this is the section of my form that pulls together the two drop down menus. Code: [Select] <form name="addfindstolocation" method="post" id="addfindstolocation"> <div align="left"> <select name=detectors id="detectorid" onchange="AjaxFunction(this.value);"> <option value=''>Select One</option> <? require "phpfile.php";// connection to database $q=mysql_query("SELECT * from detectors WHERE userid='1'ORDER BY 'detectorname' ASC"); while($n=mysql_fetch_array($q)){ echo "<option value=$n[detectorid]>$n[detectorname]</option>"; } ?> </select> </div> </div> <p align="left"> <label></label> <label>Search Head Used</label></p> <div> <div align="left"> <select name=searchheads id="searchheadid"> </select> </div> The drop down menus work fine, but I'm having a little difficulty with the data that is being saved. For the 'detectors' drop down menu the data being saved upon a selection being made is the 'id' pertient to the relevant detector e.g. 'Detector1' is selected and the 'id' value of '1' is saved which is exactly what I want. However when it comes to the second drop down menu, the value saved is the text value that the user selects, rather than the 'id'. e.g. 'Deep Search Head ' rather than an 'id' of '1'. Could someone perhaps tell me please what I need to change so that the 'id' value is saved rather than the text value. If it helps, the coding is taken from the following http://www.plus2net.com/php_tutorial/ajax_drop_down_list.php. Many thanks and kind regards. Chris Okay, so, here's the scenario. I have a form that is editing an item that is already in the database. The text fields fill in just fine with that info. However, the drop down menus don't retrieve that info, rather resorting to the defaults, which can be a problem if you don't remember what you originally had. Is there anyway to make the dropdown menus pull the info from the table and use that rather than resorting back to the default? I tried using this: Code: [Select] <tr><td width="20%">Bonus:</td><td><select name="bonus" value="{{bonus}}"> <option value="Attack" {{bonus1select}}>Add to the attack power of weapon</option> <option value="Defense" {{bonus2select}}>Add to the defensive power of armor</option> <option value="None" {{bonus3select}}>No effect</option> </select><br /></td></tr> So, it's obvious the "value" portion not working. Any help would be great!! Hi, i know this is probably very basic but i have been banging my head and looking for tuts. i have built a mysql php dropdown menu. all displays fine. now, how do i get the menu to actualy take me to a new url? the new url should be www.mysite.com/"menu selection" Code: [Select] <? include_once 'includes/db.php'; $result = mysql_query("select * from crimerate WHERE DISTRICT = 'Limpopo'", $con); if (!$result) { die('Invalid query: ' . mysql_error()); } $options=""; while ($row=mysql_fetch_array($result)) { $id=$row["id"]; $crime=$row["CRIME"]; $options.="<OPTION VALUE=\"$id\">$crime</option>"; } ?> <SELECT NAME=crime> <OPTION VALUE=0>Choose <?=$options?> </SELECT> im fairly new to php so tend to do trial and error..... more error than trial tbh. im wondering if it is possible to get a drop down menu to fill from a mysql database and to arrange it alphabetically. i have created the menu just dont know how to arrange it better. also how can i use the items id in drop menu to load other info from that row on the database. hope you can help me. Code: [Select] <FORM> <?php $result = mysql_query( "SELECT * FROM movie_info" ) ; echo "<select name= film onChange='submit()' >film name</option>"; while ($nt=mysql_fetch_array($result)){ ?> <?php echo "<option value='$nt[id]'>$nt[title] </option>"; } ?> </select> </FORM> I'm trying to code a drop-down menu that has four options; one for pie,exp, root 3, and the golden ratio.(all math values) Beside the drop-down menu, there is an option for user-inputted data, they must input only positive numbers. I must take there selected drop-down menu option and times it by the user inputted number. I'm not sure how to check which option the user chose.
<form id="s" method="post"> </select> <input type="submit" name="Submit" value="Send"> Everything That ive tried has failed Hi I have a temporary web page with a drop down menu. Problem is to get rid of the gap on the drop down menus. Any help please
www.des-otoole.co.uk/top_menu
I did search this up but all of them were lists.
I want to make a menu drop down like so....
Non-clicked...
Clicked...
The grey boxes would be images (unless it is easier to code them).
I am a complete noob so please don't use technical terms
Thanks
helo i a newbie in php. i need some help regarding my system. i want my data from database to display in drop down menu form.anyone have idea how to do that? i really need some help. i have search all over and couldn't find any solution. any suggestions would be helpful Hi i currenlty have adrop box filled with companies so the user can select which company they woudl like services from but the default is currently 0 and is to selecvt all firms but im unsure how to do this. Current code: Code: [Select] <td>Taxi Firm</td><td> <select name="taxifirm"> <option value="0" selected>All Taxi Firms</option> <?php $sql = mysql_query("SELECT * FROM taxi_Firms"); while($row = mysql_fetch_array($sql)){ $uid = $row["Firm_ID"]; $username = $row["Firm_Name"]; echo '<option value="'.$uid.'">'.$username.'</option>' ; } ?> amny help is welcomed thanx Hello! This is my first post here. I'm usually do programming in Ruby (Rails) but for a special occasion I need PHP. So hi PHP people! I come in peace My question is quite simple. How do you make a drop down menu? Most preferably with database populated fields in it. In the Rails community, this really helped me make these menus in Rails: http://www.kahfei.com/?p=23 Could someone briefly write something like that too? (The place holders) Orrr you guys can just explain how to do it. The ones I found on the internet were quite confusing and not explained enough. Help anyone? Thank you Hi, I'm no pro at PHP but I am trying to get a drop down menu to a authenticate before moving to the next part of the form. What I want is once a selection has been made, ONLY THEN can the user move on, OTHERWISE a message echo appears. This is the html menu box <select size="1" name="title"> <option>Please Select</option> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Ms">Ms</option> <option value="Dr">Dr</option> </select> Then this is what I have in the form PHP: $visitortitle = $_POST['visitortitle']; if ( HOW DO I GET THIS PART TO AUTHENTICATE AN OPTION HAS BEEN SELECTED? ) { echo "<p>Please enter a title correctly<br />before you try submitting the form again.</p>\n"; die ( '<a href="pef.html">click here go back and try again</a>' ); echo $id;} If anyone can help me sort out this part of the form I can move on as the rest is working fine? Thanks Gary I am trying to get the drop downs to work in this order on the second <li> 903,896,898,1513 but they won't. I think it's picking up ascending order maybe? Is there another php/include I should use? It's a WordPress site. Code: [Select] <div id="navigation"> <div id="navbar_menu"> <ul id="nav_menu"> <li><?php wp_list_pages('include=3&title_li=&depth=2');?></li> <li><?php wp_list_pages('include=2,903,896,898,1513&title_li=&depth=2');?></li> <li><?php wp_list_pages('include=23,911,913&title_li=&depth=1');?></li> <li><?php wp_list_pages('include=25,921,925,927&title_li=&depth=1');?></li> <li><?php wp_list_pages('include=27&title_li=&depth=2');?></li> <li><?php wp_list_categories('include=3&title_li=&depth=2');?></li> <li><?php wp_list_pages('include=407&title_li=&depth=2');?></li> </ul> </div> </div> Thanks in advance! [attachment deleted by admin] I'm having a problem with populating a second drop down menu that needs to be identical to the first from a mysql database. I have about 20 items in the DB & I only want to show the first 9. My code is: Code: [Select] <select name="a_type" style="width: 175px;"> <option value="" selected="selected"> None selected</option> <?php $i=1; while (($_produce = mysql_fetch_array($result_produce)) && ($i <=9 )) { $produce_type=$_produce["type"]; $produce_id=$_produce["id"]; $i++; ?> <option value="<?php echo $produce_id; ?>"><?php echo $produce_id; ?> - <?php echo $produce_type; ?> </option> <?php } ?> </select> That works fine in my first drop down menu but the second drop down menu with the same exact code will show items starting at 11 & higher instead of 1 to 9. I haven't tried closing the DB & the reopening it which I assume would work but there are a lot of other variables & things I'd have to check to make sure they don't get effected so I'd rather not. Is there a simple way to solve this? I have lots of tables for my products could i use the table name for a drop down menu? or is it not safe Thanks for any help Hey guys im looking to do a drop down menu which is pretty basic however, in this drop down menu it uses an array of 4 values eg Orange, Apples, Bananas, Strawberry's. For this menu if a user has previously chosen an Orange which is stored on the db then then when the drop down menu is loaded it should move Orange to the top of the list, the same applies for the other values. How could I do this? I know how to do the select statement and place the values in an array. from there I dont know quite how to approach it. () Thank you. Hi guys, I had a problem before which is similar to the problem im about to describe, however Pikachu helped me solve the last problem so a big thanks to him! However this problem is slightly different and im struggling to find a solution. I will first describe the problem I had which pikachu helped me solve as it would be easier for me to describe this past problem. I have an update form, so a user can edit existing records which are pulled from a database. When the user changes the values in a text field then submits the form, the values in the text fields updates fine. However if they change the values in the text box and then tries to submit the form but there was an error, the values in the text fields go back to the values from the database and the user has to change the text fields again. Well this problem was solved with the help of pikachu and the this is what I did... <?php if(isset($_POST['title'])){echo htmlspecialchars($_POST['title']);} else if (isset($title)) {echo htmlspecialchars($title);}?> Again, the above works fine however the problem I have now is the same problem as described above however it relates to drop down menus and not text fields. I can't seem to figure out how to retain the values in a drop down menu the same way I have for text fields. Below is the code that im using that I thought would work however it isnt working, the values of the drop down menu (if there was an error) are going back to the values from the database. Heres the code... <option value="Psychopathic" <?php if ((isset($_POST['category']))&&($_POST['category'] == 'Psychopathic')) { echo ' selected=selected'; } else if ((isset($category))&&($category == 'Psychopathic')) { echo ' selected=selected'; } ?>>Psychopathic</option> Does anybody know what i am doing wrong and how i can fix this problem? I understand what i need to do but i cant seem to get the code to do what i want to do and thats to retain values of a drop down menu when the page is returned with an error. Any help would be much appreciated. AJay Hey guys I wasnt sure if this is a php topic or java script im trying to make my drop down menu's activate onchange. what confuses me is how do I make php know that the java script is being run. Or have the java script trip my php code. To know a button has been pressed i use "if (isset['_POST'])" echo '<select name="siege_list" id="siege_list">'; foreach($name as $key => $value) { echo '<option value="' . $value['name'] . '" ' . ($value['name'] == $current1 ['name'] ? 'selected="selected"' : '') . '> ' . $value['name'] . '</options>'; } echo '</select><input type="submit" id="siege_planet" onchange="this.form.submit()">'; Hey Guys, I'm building a site and I need a drop down menu created dynamicly.... This is the flat html code Code: [Select] <div class="art-nav"> <div class="l"></div> <div class="r"></div> <ul class="art-menu"> <li><a href="URL 1"><span class="l"></span><span class="r"></span><span class="t">TOP LEVEL</span></a> <ul> <li><a href="URL 1">SUB CAT 1</a></li> <li><a href="URL 2">SUB CAT 2</a></li> <li><a href="URL 3">SUB CAT 3</a></li> </ul> </li> <li class="art-menu-li-separator"><span class="art-menu-separator"></span></li> <li><a href="URL 5"><span class="l"></span><span class="r"></span><span class="t">Contact Us</span></a></li> </ul> </div> This is the code that shows a dyamic code, but not in the menu... <?php wpsc_start_category_query(array('category_group'=> get_option('wpsc_default_category'), 'show_thumbnails'=> get_option('show_category_thumbnails'))); ?> <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_link"><?php wpsc_print_category_name();?></a> | <?php wpsc_print_subcategory(); ?> <?php wpsc_end_category_query(); ?> I am having issues with my page. I am trying to send a email to a different address based on the entry that my user submits. Here is my form on my test page. Code: [Select] <form method=POST action=formdata.php> <table width="640" border=0 align="center"> <tr> <td align=right><b>Test</b></td> <td><input type=text name=test size=25></td> <td> </td> <td> </td> </tr> </table> </dl> <div align="center"> <p> <input type=hidden name=FA value=SendMail> </p> <input type=submit value="Submit Form"> </p> </div> </form> here is the php code for my formdata page Code: [Select] <?php $con = mysql_connect("localhost","test","test"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $sql="INSERT INTO formdata (test) VALUES ('$_POST[test]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Your Information Was Successfully Posted"; mysql_close($con); if ($_POST['test'] =="A"){ $to = "email@sample.com"; $subject = "Custom Form"; $message = $_POST['test'] ; $headers = "From: email@sample.com"; $sent = mail($to, $subject, $message, $headers) ; } else if ($_POST['test'] =="B"){ $to = "email2@sample.com"; $subject = "Custom Form"; $message = $_POST['test'] ; $headers = "From: email@sample.com"; $sent = mail($to, $subject, $message, $headers) ; } if($sent) {print "<p>Your mail was sent successfully"; } else {print "<p>We encountered an error sending your mail"; } ?> |