PHP - Drop Down Menu Php
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 Similar Tutorialshelo 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 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> 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 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> 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
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!! 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
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 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] 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 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. 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? 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 all, I'm just wondering if there's an easier way of doing what accomplishing the following: I have a value in my database which represents a selection in a drop down menu, i want to read it from the database and have it automatically selected depending on the stored data. I have the following working but just wondered if there was an easier way to get the same result: Code: [Select] <?php //database connection $query = "SELECT id FROM `tablename` WHERE username='$username'"; $result = mysql_query($query); $row = mysql_fetch_object($result); $id = $row->id; $id = (int)$id; ?> <select name="id"> <option value="">Select your option...</option> <option value="1" <?php if (($id - 1) === 0) { echo 'selected="selected"'; }?>>Selection 1</option> <option value="2"<?php if (($id - 2) === 0) { echo 'selected="selected"'; }?>>Selection 2</option> </select> Sorry if it's not very clear, i'll explain best i can if anyone can help. Thanks Hi I have coded a drop down menu with php and i am trying to retrieve the data when a user select a option from the menu and the data is retrieved from the database. So far i have tried and nothing is displaying when i tried to process the php form. Sales.php Page <form action="saleprocess.php" method="GET"> <?php echo 'Product Model:'; $query="SELECT * FROM products"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=product_model value=Select>Product Model</option>"; // printing the list box select command while($rows=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option name=product_model value='.$rows[product_id].'>$rows[product_model]</option>"; /* Option values are added by looping through the array */ } echo "</select><br>"; ?> <input type='submit' name='submit' value='Create'></input> <br> </form> ******************************************************************************** Salesprocess.php page <?php include("connect.php"); if(isset($_GET['product_id'])){ $product_id = $_GET['product_id']; $query = mysql_query("SELECT * FROM products WHERE product_id= $product_id"); while($rows = mysql_fetch_assoc($query)) { echo 'Product Model<br>'; echo $rows['product_id']; echo $rows['product_model']; } } ?> Muchly appreciated if someone can help me 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> I'm trying to make it so that someone can add an item to the shop based upon the current items within the database. How do I go about doing that? I know i have to change <input> to <select>, but beyond that, how do I code it so I can run an array to get all the current items from the table `items` and list them by their `name` field? Thanks in advance! Here is what I have so far: function addshopinv($id) { error_reporting(E_ALL); ini_set('display_errors', 1); if (isset($_POST["submit"])) { extract($_POST); $errors = 0; $errorlist = ""; if ($name == "") { $errors++; $errorlist .= "Name is required.<br />"; } else if ($errors == 0) { $dbh=dbconnect() or die ("Userlist read error: " . mysql_error()."<br>"); mysql_select_db("XXX"); $query = mysql_query("SELECT id FROM items WHERE name='$name'"); while ($result = mysql_fetch_array($query)){ $item_id = $result['id']; $query1 = mysql_query("INSERT INTO sale SET shop_id='$id', item_id='$item_id'"); } admindisplay("Inventory Item Added.","Add New Inventory Item"); } else { admindisplay("<b>Errors:</b><br /><div style=\"color:red;\">$errorlist</div><br />Please go back and try again.", "Add New Item to Shop"); } } $page = <<<END <b><u>Add New Inventory Item</u></b><br /><br /> <form action="admin_panel.php?do=addshopinv:$id" method="post"> <table width="90%"> <tr><td width="20%">Name:</td><td><input type="text" name="name" size="30" maxlength="255" value="" />*255 character max</td></tr> </table> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /> </form> END; $page = parsetemplate($page, $row); admindisplay($page, "Add New Inventory Item"); } Hi I'm new here, also I'm new in php. What I need to do is to write registration form with drop down menu. Actually, I need to have drop down menu which would write data into database when someone fill registration form. Also I need when someone choose one of the city name in drop down menu, to display certain image in specific php page. Can anyone help me. Here is my code for registration form : register.php <?PHP //Database Information $dbhost = ""; $dbname = ""; $dbuser = ""; $dbpass = ""; //Connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = md5($_POST['password']); $grad = $_POST['grad']; // lets check to see if the username already exists $checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); $username_exist = mysql_num_rows($checkuser); if($username_exist > 0){ echo "I'm sorry but the username you specified has already been taken. Please pick another one."; unset($username); include 'register.html'; exit(); } $checkemail = mysql_query("SELECT email FROM users WHERE email='$email'"); $email_exist = mysql_num_rows($checkemail); if($email_exist > 0){ echo "Email koji ste izabrali vec postoji."; unset($email); include 'register.html'; exit(); } $checkname = mysql_query("SELECT name FROM users WHERE name='$name'"); $name_exist = mysql_num_rows($checkname); if($name_exist > 0){ echo "Ime koje ste izabrali vec postoji."; unset($name); include 'register.html'; exit(); } // lf no errors present with the username // use a query to insert the data into the database. $query = "INSERT INTO users (name, email, username, password, grad) VALUES('$name', '$email', '$username', '$password','$grad')"; mysql_query($query) or die(mysql_error()); mysql_close(); if(empty($name) || empty($email) || empty($username)) { echo "Nisu uneseni svi podaci."; } /*else if(empty(($password))) //ovaj uslov ne prolazi !!! { echo "Niste uneli lozinku."; }*/ else { echo "Uspesno ste se registrovali"; } ?> and for form : register.html <form name="login" method="post" action="register.php"> <table border="0" width="225" align="center"> <tr> <td width="219" bgcolor="#ff6600"> <p align="center"><font color="white"><span style="font-size:14pt;"><b>Registration</b></span></font></p> </td> </tr> <tr> <td width="555"> <table border="0" width="555" align="center"> <tr> <td width="116"><span style="font-size:12pt;">Name:</span></td> <td width="156"><input type="text" name="name" maxlength="100"></td> <td width="200"><p align="left"><span style="font-size:11pt;"><i>*Ukucajte vase puno ime i prezime*</i></span></p></td> </tr> <tr> <td width="116"><span style="font-size:12pt;">Email:</span></td> <td width="156"><input type="text" name="email" maxlength="100"></td><br/> </tr> <tr> <td width="116"><span style="font-size:12pt;">Username:</span></td> <td width="156"><input type="text" name="username"></td><br/> </tr> <tr> <td width="116"><span style="font-size:12pt;">Password:</span></td> <td width="156"><input type="password" name="password"></td><br/> </tr> <tr> <td width="116"> </td> <td width="156"> <p align="right"><input type="submit" name="submit" value="Submit"></p> </td> </tr> <tr> <td> <select name = "dropdown" value="options"> <option value "register.php">Izaberi grad</option> <option value = "Beograd">Beograd</option> <option value = "Nis">Nis</option> <option value = "Novi Sad">Novi Sad</option> </select> </td> </tr> </table> </td> </tr> <tr> <td width="219" bgcolor="#ff6600"> </td> </tr> </table> </form> I am brand new to php and I don't know where I am going wrong with this. I would like to have drop down menu which is populated from mySQL and which would allow user to select one option. The selection would be used on the following page once the form is submitted. Right now I have the following script and it populates the dropdown menu but it does not return value when selection is made. <form action="databaseinputcheck2.php" method="post"> <?php mysql_connect("localhost", "xxxxxxxxxxxx", "xxxxxxxxxxxxxx") or die(mysql_error()); echo "Connected to MySQL<br />"; ?> <p>Lotteries: <?php mysql_select_db("wpawlowski") or die(mysql_error()); // Get all the data from the "LotteryNames" table $lotterynameresult = mysql_query("SELECT id, Name FROM LotteryNames") or die(mysql_error()); ?> <select name="LotteryName" size="1"> <option selected value="">Select One</option> <option value="">----------</option> <?php // keeps getting the next row until there are no more to get while($currentlottery = mysql_fetch_array( $lotterynameresult )) { $lid=$currentlottery['id']; $lname=$currentlottery['Name']; // Print out the contents of each row into drop down menu echo "<option value='$lid'>$lname</option>\n"; //$options.="<OPTION VALUE=\"$lid\">".$lname; //Selection input line } ?> <input type="submit" value="GO" /> </form> I looked on the internet and it is my understanding that if I comment out the line starting withc "echo" and uncomment the one below the drop down menu should still be populated and the selection would be stored in the $options variable which in turn could be transfered to databaseinputcheck2.php with $_POST to be used there, but when I do uncomment that line and comment the echo line out my drop down menu is not populated, what am I doing wrong? |