PHP - Dropdown, Passing Selected Values In A Formate So It Matches Url_redirect Patter
Folks,
I have a dropdown, once values are selcted, these values should be put in a URL structure so that it matches with the one MoD_rewrite rule in my .htaccess. Here is my Mod_Rewrite Rule: RewriteRule ^(.*)/([^/]*)\.html$ search.php?q=$1&sc=$2 [QSA,L] Here is my Dropdown Code: <div id="search" > <form id="searchform" method="get" action="search.php"> <label>Search By Brand/ Manufacturer: </label> <select name="q"> <option value="SelectBrand">Select Brand</option> <?php if(isset($this->search->options)): ?> <?php foreach($mfg as $lolachild): ?> <option value="<?php echo $lolachild; ?>"><?php echo ucwords($lolachild); ?></option> <?php endforeach; ?> <?php endif; ?> </select> <select name="sc"> <option value="All"><?php eprint(LangAll); ?></option> <?php if(isset($this->search->options)): ?> <?php foreach($this->search->options as $cat): ?> <option value="<?php echo $cat->value; ?>"><?php echo $cat->name; ?></option> <?php endforeach; ?> <?php endif; ?> </select> <input type="submit" value="<?php eprint(LangSearch); ?>" /> </form> </div> Problem is, upon Submit, it goes to this link structu http://mydomain.co.uk/search.php?q=fisher&sc=302 It should rather be: http://au2.co.uk/fisher/302.html What am i missing or doing wrong? Cheer Natasha Similar TutorialsHi, I am doing an EDIT user page and would like to check records with a dropdown and then set as selected, please help! <select name="BrokerID" class="small-input"> <option value="Please select an option">Please select a Broker</option> <?php while($row2 = mysql_fetch_array($broker)) { echo '<option name="BrokerID" value="'.$row2['BrokerID'].'">'.$row2['BrokerName'].'</option>'; } ?> </select> Hi freaks, I'm new to php first of all. I'm dynamically binding a dropdownlist with mysql database . After the user selects an item from it , I want to match that item with another table so as to populate another database. The code I'm using to populate dropdown: Code: [Select] <?php $con = mysql_connect("localhost","root",""); if(!$con) { die ('Can not connect to : '.mysql_error()); } mysql_select_db("ims",$con); $result=mysql_query("select cat_id,cat_name from category"); echo "<select name=cat>"; while($nt=mysql_fetch_array($result)) { echo "<option value=$nt[cat_id]> $nt[cat_name] </option>"; } echo "</select>"; mysql_close($con); ?> Now after the user selects any one of the item , I want to bind another dropdown on the same page using such query like $result=mysql_query("select subcategory.sc_id,subactegory.sc_name from subcategory,category where subcategory.sc_id=$nt[cat_id]"); Please anyone tell me the logic and code to do it. Also tell me do I need an intermediate page to post the 1st dropdown value and then continue with 2nd dropdown. I couldn't figure out the concept anyhow. Help on this will be highly appreiable . (Tell me if I'm not clear with my question) The rest of my coding works however this part does not and I'm trying to figure out why. I'm sure my syntax isn't right so I hope someone can correct my mistake. $contentpageID = $_GET['id']; $query = "SELECT contentpages.contentpage, contentpages.shortname, contentpages.contentcode, contentpages.linebreaks, contentpages.backlink, contentpages.showheading, contentpages.visible, contentpages.template_id FROM contentpages WHERE contentpages.id = '" . $contentpageID . "'"; <label for="template">Template</label> <select class="dropdown" name="template" id="template" title="Template"> <option value="0">- Select -</option> <?php $query = 'SELECT * FROM templates'; $result = mysql_query ( $query ); while ( $template_row = mysql_fetch_assoc ( $result ) ) { print "<option value=\"".$template_row['id']."\" "; if($template_row['id'] == $row['template_id']) { print " SELECTED"; } print ">".$template_row['templatename']."</option>\r"; } ?> </select> I must be missing something simple. I've got this little script that pulls rows from the database to populate a dropdown. If one of them matches a predetermined variable, then I want it to show selected. It's... almost working. The dropdown prints, and shows the options. But the selected item shows separate, printed just below the dropdown? Here's what I've got: Code: [Select] <?php $quer3=mysql_query("SELECT discount_id, discount_name,discount_amount FROM tbl_discount order by discount_amount"); echo " <select name='discount_id'><option value=''>Select</option>"; while($row = mysql_fetch_array($quer3)) { if($row[discount_id]==$discount_id){echo "<option selected value='".$row[discount_id]."'>".$row[discount_name]." / $".$row[discount_amount]."</option>";} else{echo "<option value='$row[discount_id]'>$row[discount_amount]</option>";} echo "</select>"; } ?> Hi I have been trying to get a value to be selected in a mysql populated dropdown list but can't get it to work and was hoping someone could help I have a database with user info in it and this is an update page where they can update their details. The code i have (which doesn't work) is: <select name="agency"> <? $query1 = mysql_query("SELECT * FROM agents ORDER BY agent ASC",$connect); while($myrow = mysql_fetch_assoc($query1)){ $agent = $myrow['agent']; echo "<option"; if ($agent == $agency) { echo "selected='selected'"; } echo ">$agent</option>"; } ?> </select> The $agency value is the current agency which is stored in the users profile and the value does exist in the list which is being populated (also, i have define $agency further up in my code) so i don't know why the selected value won't display. No value is displayed in the dropdown list on the page - but the values are in the list if i remove the selected='selected' part of the code. Any help yould be greatly appreciated. Merry Christmas Andy mysql.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ckeditor",$con); ?> --------------------------------------------------------- add.php <?php include("mysql.php"); if(isset($_POST["button2"])) { $sql="INSERT INTO cktext (section) VALUES ('$_POST[select2]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } ?> ----------------------------------------------------------------- home.php <form id="form1" name="form1" method="post" action="add.php"> <tr> <td>Section:</td> <td><select name="select2" id="select2"> <option selected="selected" value="MALE">Male</option> <option selected="" value="FEMAIL">FEMAIL</option> </select></td> </tr> <input type="submit" name="button2" id="button2" value="Upload" /> </form> In DATABASE :- cktext table attribute "section" is varchar type. BUT IT RETURN ME BLANK OUTPUT. i have the following code: <td width='100px'>Suppliers <select name="supplier"> <?php $catcher_id = $service->getCatcherId(); $supplier_names = LpmAdnetworkPeer::getByName($catcher_id); foreach($supplier_names as $row) { ?> <option><?php echo $row->getName(); ?></option> <?php } ?> </select> </td> then on the same form i have a submit button that takes me to the next form..the problem now is how can i access the ID of the item seleted in the dropdown on the NEXT form please? i can get the name from the list by $_POST['supplier'] on the next form thanks i skipped solving this the other day with an easier way but now i am stuck with this stumble again in another area and i have no way out.... so here it goes, i have an ajax dropdown box...i need to get the value that is selected by the user when it is clicked and then pass this value to a new pop window by appending to its url....any suggestions? friend the code display all the managers name
<?phpand the variable below displays the result $Manager= $row['Manager'] ; but how do i do it on the above dropdown list the it shows which result is in the $Manager variable? I'm just attempting to learn how PHP handles things and I can't quite wrap my head around how to apply Selected to the final Option and show the Traits for the Character based on the Selected Option. I understand this might need POST, if it does, I would appreciate a bit of help on how I would set this up as POST since I didn't think a drop down required a submit button. Code: [Select] $character= array (array(Name=>"Barry","Class"=>"Fighter",Level=>1,Str=>10,Dex=>10,"Int"=>10),array(Name=>"Lindehar","Class"=>"Ranger",Level=>1,Str=>10,Dex=>10,"Int"=>10),array(Name=>"Verelden","Class"=>"Mage",Level=>1,Str=>10,Dex=>10,"Int"=>10)); print "Select a Character:<br /><select>"; foreach($character as $array_num) { foreach($array_num as $char_trait=>$trait_value) { if($char_trait==Name) { $selected_value=""; $generated_chars="<option selected=".$selected_value." value='".$char_trait."'>".$char_trait.": ".$trait_value."</option>"; print $generated_chars; if($selected_value=/".$char_trait.": Barry"/") { foreach($char_trait=="Barry") { print "<h4>".$char_trait.": ".$trait_value."</h4>"; } } } } } print "</select><p />"; I'm new to this form and php/mysql so sorry if this isn't the right place to post this. This is what is in the first dropdown box. Code: [Select] $selValues['john'] = "a, b, c, d, e"; These are the different lists I want it to put in the second drop down box depending on what they choose in the first. Code: [Select] $selValues['list1']= " a1, a2, a3, a4, a5"; $selValues['list2']= " b1, b2, b3, b4, b5"; This is how I made an attempt to make it work before posting here. Along with plently of other ways. Code: [Select] if ($selValues['john']=a) { $chan_input = selectBuilder($selValues['$list1'] }; else if ($selValues['john']=b) { $chan_input = selectBuilder($selValues['$list2'] }; Basicly how I need it to work is there are two drop down boxes. First they will chose between a,b,c,d,e. If they chose a then on the second drop down box I only want them to be able to select a1,a2,a3,a4,a5. Hey Everyone... First off, I am only a young web developer and i'm working on a school project and am making a text-based game online... Now what i'm having trouble with... I want a drop-down list that has a list of characters classes Clubber Mixer Sauceror Tamer And I want whatever is selected to be placed into the database along with the username/password (THIS ALL WORKS FINE JUST NOT THE DROP DOWN LIST) All help appreciated Yesterday, I created a topic about how I could update records and I managed to achieve that successfully. Now I have another dilemma. When I have a specific record I want to update, I want to change a category ID of an product (e.g. change it from 1 to 2) but how do I go about doing this? Here is my code thus far: Code: [Select] <?php require_once ('./includes/config.inc.php'); require_once (MYSQL); $id=$_GET['prodID']; $results = mysqli_query($dbc, "SELECT * FROM product WHERE prodID=".$_GET['prodID'].""); $row = mysqli_fetch_assoc($results); ?> <form action="" method='POST'> Product ID: <input type="text" value="<?php echo $row['prodID'];?>" name="prodID" /> <br /> Product: <input type="text" value="<?php echo $row['product'] ;?>" name="product" /> <br /> Product Description: <input type="text" value="<?php echo $row['prod_descr'] ;?>" name="prod_descr" /> <br /> Category: <select name="category"> <option value="<?php echo $row['catID'];?>"></option> </select> Price: <input type="text" value="<?php echo $row['price'] ;?>" name="price" /> <br /> In Stock: <input type="text" value="<?php echo $row['stock'] ;?>" name="stock" /> <br /> <br /><input type="submit" value="save" name="save"> </form> <?php if(isset($_POST['save'])) { $id = $_POST['prodID']; $product = $_POST['product']; $descr = $_POST['prod_descr']; $price = $_POST['price']; $stock = $_POST['stock']; // Update data $update = mysqli_query($dbc, "UPDATE product SET product='$product', prod_descr='$descr', price='$price', stock='$stock' WHERE prodID=".$_GET['prodID'].""); header( 'Location: update_save.php' ) ; } ?> I have created a query to show the subject name as a drop down box now I would like to you use value to compare what module available in the database. For now I can disaplyed all the module that is avilable for all the subject. But i would like to use the drop down box to gather which subject they have chosend then use this information to gather the module $query=("SELECT Tes_Name FROM User u, Subject s, Test t WHERE u.Use_ID = '{$_SESSION['ID']}' AND s.Sub_ID=t.Sub_ID "); <Html> <?php session_start(); $Value1 = mysql_real_escape_string(trim($_POST['myselect'])); $_SESSION['myselect'] = $Value1; //echo $Value1; include '../Database/connection.php'; ?> <body> <form action="Previousq_Module2.php" method="post"> <?PHP include '../Database/Module_Exsit.php'; $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<select name=select>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['Tes_ID'].">".$row['Tes_Name']."</OPTION>"; } echo "</select>"; ?> <input type="submit" value="submit"/> </form> </body> </html> I have several drop down boxes. When submit is clicked it execute query on another page. Problem is when submit is clicked selected values are return to defaults. Is it possible for the values to be remembered after submitting them? Part of the drop down code: Code: [Select] <?php $result = mysql_query("SELECT * FROM product GROUP BY Rim"); ?> <select id="Rim" name="Rim" selected="selected" style="width:158px;position:static;z-index:-1;"> <option value="rim" selected="selected"><?php echo "Rim"; ?></option> <?php while ($row = mysql_fetch_array($result)) { echo "<option>" . $row['Rim'] . "</option>"; echo "<br />"; } ?> </select> Hi, I have a form for news articles. It has a title and a body which is fine. I also have a search box that allows the user to search for a memeber and click their name when it appears. This moves a div with a data-id into another div. The purpose of this is to tag them in the article. I am able to post all of the simple stuff but how would i post these value. I am assuming that i would need to create an array of said values but i am struggling to get them showing in post at all. Here is the code i have so far <?php function searchForPeople($searchVal, $exclude = '0'){ $sv1 = $searchVal; $sv2 = $searchVal; include 'includes/dbconn.php'; $out =""; $stmt = $conn -> prepare(" SELECT fname, lname, id FROM person WHERE id NOT IN (".implode(',', array_map('intval', $exclude)).") AND (fname LIKE CONCAT('%',?,'%') OR lname LIKE CONCAT('%',?,'%')) "); $stmt -> bind_param('ss', $sv1, $sv2); $stmt -> execute(); $stmt -> bind_result($fn, $ln, $pid); while($stmt -> fetch()){ $out .= "<div class='btn btn-primary m-1 tagInArticle' name='taggedPerson[]' data-id='$pid'>$fn $ln</div>"; } return $out; } ?> ...... <div id="searchResultsHere"> <!-- ajax content here --> </div> <hr> <div id="taggedInArticleContainer"> <!-- ajax content here --> </div> ....... <div class="col-lg-2"> <button type="submit" name="PublishNewNews" class="btn btn-primary w-100 mb-3">Publish</button> <button class="btn btn-primary w-100">Save</button> <hr> <div class="btn btn-warning w-100 mb-3">Private</div> <input type="hidden" name="howVisible" value="Private"> <hr> <p class="text-justify">Private news articles will only be avilable to logged in users</p> </div> ....... <script> $('#searchResultsHere').on('click', '.tagInArticle', function tagInArticle(){ var tagButton = $(this); tagButton.appendTo('#taggedInArticleContainer') }); $('#searchForPeopleBox').keyup(function(){ var searchVal = $(this).val() var tagged = '0' var tagged = $('#taggedInArticleContainer').find('.tagInArticle').map(function(){ return $(this).data('id'); }).get(); $.ajax({ type: 'post', data: {"ajax" : 'one', "val" : searchVal, "exclude" : tagged}, success: function(resp){ $('#searchResultsHere').html(resp) } }) }); </script> I hope this is enough to go on. I am sure it is simple but i just cant get it. Thanks all in advance. Hi all.
how can i make the values show like a list. I tried html line break "<br>" and php \n but all to no avail. It just show all the values in one straigth line.
example of what i want is for the values to appear like this:
1234567890
0987654345
4567890675
instead of :
1234567890 0987654345 4567890675
Thanks
<form data-abide method="post" action=""> <div> <select name=""> <option value="name"> <?php $stmt = $pdo->query("SELECT acct_num FROM table order by id desc"); while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) { echo $row['acct_num']; } ?> </option> </select> </div> <div> <label>New Password <small>required</small></label> <input type="password" name="password" id="password" required> <small class="error">New password is required and must be a string.</small> </div> <div> <label>Confirm New Password <small>required</small></label> <input type="password" name="password2" id="password2" required> <small class="error">Password must match.</small> </div> <input name="submit" type="submit" class="button small" value="Change Password"> </form> Edited by Mr-Chidi, 13 November 2014 - 01:34 AM. Hello, I have a datepicker that when a date is selected, the post to a php file will get the sum values for that selected day, month, and year. I have the "by day" working with this... <?php $choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d"); $con = mysql_connect("localhost","root","xxxxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = "SELECT sum(power/1000) AS choice FROM feed WHERE date = '".$choice."' group by date"; $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); $row = mysql_fetch_assoc($res); echo $row['choice'].'<br />'; ?> But by month and year are not clicking... Help Please Alan |