PHP - Retrieving An Html Dropdown Select
I'm trying to pull up an identical form after submission by using its "id" and ECHO for the form lines.
Question: What is the correct approach for ECHOing an HTML dropdown that is written as: <select name='chixcutlet' value='' > <option value='0.00' selected> --- </option> <option value='1.00'> 1 </option> <option value='2.00'> 2 </option> <option value='3.00'> 3 </option> </select> I want it to get the info from the database so that the option that is saved in the database will be new default when the page is loaded. If I don't change it to the previous info it will update the database with the default option rather then the actual option. Similar Tutorialshello, im only getting the second half of my results showing in my dropdown box. here is my code. Code: [Select] if(isset($_GET['id'])) { $uid = $_GET['id']; } $forward = mysql_query("SELECT * FROM players WHERE status = '1' AND position = 'forward' ORDER BY name"); $forward1=""; while($row1 = mysql_fetch_array($forward)) { $forwardid=$row1["id"]; $forwardname=$row1["name"]; $forwardteam=$row1["team"]; $forward1.="<OPTION TITLE=\"$forwardteam\" VALUE=\"$forwardid\">".$forwardname.'</option>'; } $result = mysql_query("SELECT * FROM picks WHERE uid = '$uid' AND pickid = 'forward1'"); while($row = mysql_fetch_array($result)) { $playerid=$row['playerid']; } if(isset($forwardpick1)) { $result1 = mysql_query("SELECT * FROM players WHERE id = '$playerid'"); while($row1 = mysql_fetch_array($result1)) { $forwardpick1=$row1['name']; } $forwardpick1="<br /><br /><font color ='#000000' size = '5'><b>$forwardpick1"; } else { $forwardpick1=" <form method='POST' action='draftpick.php' name='forward1'> <p><font color='#000000'><select size='1' name='player'> <?php echo '$forward1'; ?> </select><br><br><input type='submit' value='Submit' name='submit'></font></p> </form> "; } any direction is appreciated. Ive tried to create a function to create a dropdown select box but im getting alot of errors to do with the if statement saying the ($_POST[$name]) value is not set??? function selectBox($name, $firstvalue, $limit, $increment) { // echo "<br>"; // echo $name; // echo "<br>"; // print_r($_POST[$name]); // echo "<br>"; $select ="selected=\"selected\""; $body = "<select name='$name' id='$name' method='POST'> <option value=''>$name</option>"; for ($value = $firstvalue; $value <= $limit; $value += $increment) { $body .= "<option value= '$value' "; if ($_POST["$name"] === $value) { $body .= $select; } $body .= ">$value</option>"; } $body .= "</select>"; // echo $value; // echo $_POST[$name]; // echo $_POST['Width']; return $body; } Any help would be greatly appreciated Hey guys, I am wanting to select a dropdown value based on the value of 'level' in the row of the user select by a $_GET. It will house the ranks of the user. Here is my script. RANK <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("chat"); $result = mysql_query("SELECT * FROM users WHERE user_id = '$_GET[id]'"); $row = mysql_num_rows($result); ?> <form id="main_form" name="main_form" method="post" action=""> <select name="rank"> <option value="0" <?php if($row['level']=="0") { echo "selected"; }?>>Unactivated</option> <option value="1" <?php if($row['level']=="1") { echo "selected"; }?>>Banned</option> <option value="2" <?php if($row['level']=="2") { echo "selected"; }?>>Regular User</option> <option value="3" <?php if($row['level']=="3") { echo "selected"; }?>>Donator</option> <option value="4" <?php if($row['level']=="4") { echo "selected"; }?>>Moderator</option> <option value="5" <?php if($row['level']=="5") { echo "selected"; }?>>Administrator</option> <option value="6" <?php if($row['level']=="6") { echo "selected"; }?>>Owner</option> </select> <input type="submit" id="main_submit" name="main_submit" value="submit" /> </form> It is not selecting for some reason at all. Can someone tell me what I am doing wrong? I have the following code currently: Code: [Select] <?php foreach ((array)$node->field_buy_at as $item) { ?> <?php print $item['view'] ?> <?php } ?> I would like to make the list a drop down with a link so that when a user selects, he goes to a new page. I tried the following: Code: [Select] <select name="select"> <?php foreach ((array)$node->field_buy_at as $item) { ?> <?php $url = $node->field_buy_at[0]['url']; $store = $item['view']; ?> <? echo "<option value='$url'>$store</option>";?> <?php } ?> </select> I'm pretty sure it's this "$url = $node->field_buy_at[0]['url'];" that I don't have correct. Hi I'm trying to create a form where people first select the number of children they have, and then a table should appear where they fill in the extra information (name, sex, dob) about every child. The code works except for that i don't know how to add the year of the date of birth of every child with a loop. Appartly i cannot use php in javascript? Any solutions? thanks! Code: [Select] function addKindForms(aantal) { if (aantal != "-") { var output = ""; output = output + "<table cellpadding='2' cellspacing='0'>"; output = output + "<tr><td><b>Naam:</b></td><td><b>Geslacht:</b></td><td><b>Geboortedatum:</b></td><td></td><td></td></tr>"; for(i=1;i<=aantal;i++) { output = output + "<tr><td><input type='text' name='kind"+i+"_name' size='15' value=''></td><td><select name='kind"+i+"_sex'><option value='m'>jongen</option><option value='f'>meisje</option></select></td><td><select name='kind"+i+"_gebdatumdag'><option value=''></option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'> 8</option><option value='9'>9</option><option value='10'>10</option> <option value='11'> 11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option></select></td><td><select name='kind'+i+'_gebdatummaand'><option value=''></option><option value='1'>jan</option><option value='2'>feb</option></select></td><td><select name='kind'+i+'_gebdatumjaar'><option value=''></option><?php for ($y=date('Y');$y>=(date('Y')-125);$y--){if($_POST['bdaykind_jaar']==$y){$selected='selected';}echo'<option value=''.$y.'' '.$selected.'>'.$y.'</option>';$selected = '';}?></select></td></tr>"; } output = output + "</table>"; document.getElementById("kindforms").innerHTML = output; } } Hi, I'm trying to retrieve the integer value between the <span> tag from a HTML source code.
HTML source code:
<span> (3861822) </span>This is the php code: <!DOCTYPE html> <html> <body> <?php //use curl to get html content function getHTML($url,$timeout) { $ch = curl_init($url); // initialize curl with given url curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error return @curl_exec($ch); } $html=getHTML("http://www.alibaba.com/Products",10); preg_match("/<span>(.*)<\/span>/i", $html, $match); $title = $match[1]; echo $title; ?> </body> </html>Whenever I try to run it, this error will come out: Notice: Undefined offset: 1 in C:\xampp\htdocs\myPHP\index.php on line 19. How to correct it so that it will display all the integer value within the tag name but without the bracket? Thanks Edited by Raex, 20 August 2014 - 01:38 AM. Hi, 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, I have a search form where users can search by age and country. Users can also save their search so they can go back and do it again but the problem is when they reload their saved search, I need it to select the country that has been saved in the drop down. So if someone searched the United Kingdom, I need it to show United Kingdom in the select drop down instead of (Select Country). Is there any easy and quick way around this? Many Thanks I'm trying to figure out why the options aren't appearing inside the select dropdown. Any ideas why? Code: [Select] echo "<label for=" . $row2['fullName'] . ">" . $row2['fullName'] . "</label>"; echo "<select name=" . $row2['fullName'] . " id=" . $row2['fullName'] . " class=dropdown title=" . $row2['fullName'] . " />"; if ($styleID == 1 || $styleID == 2 || $styleID == 6) { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID = 3 ORDER BY characters.characterName"; $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $row3 = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r"; } } else { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID IN (1,2,6) ORDER BY characters.characterName"; $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $row3 = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r"; } } echo "</select>"; } Hi, I'm a php newbie, with some mysql experience. I have a mysql database as follows: Database=watch, Table=events - fields id, reportno, sdate, comments What I need is: 1. A dropdown list to display reportno from mysql database. 2. Depending on which reportno I choose, I'd like to open a popup(or separate) page to display the stored information. Tks in advance for any help I am querying a database and trying to display the names of categories in a drop-down menu. My problem is that the names are not visible. I have the following code: $result = mysql_query('SELECT name FROM category') or die(mysql_error()); echo('Choose a category'); echo('<select name="category">'); echo('<option value="general" >general</option>'); while($row = mysql_fetch_array($result)){ echo('<option style="color:black;" value = "'.$row['name'].'">'.$row['name'].'</option>'); } echo('</select><br /><br />'); The query is good and executing the query retrieves the expected number of results. My dropdown box is the proper length and width (showing that it is trying to print the names); however, nothing is displayed. Any ideas? Hello forum,
So I've been developing an app mostly in PHP, but am rather afraid of JS. Hope to fix that.
I have an AJAX dropdown using JQuery to search locations. It works great. However, I want to make it similar to what is seen on this site:
http://placefinder.com/
As you can see, the dropdown, when clicked populates a box. Then the user submits the form and the data is used in the application.
I have no clue how to make the form populate with data from the DB (I'm using mySQL) when clicked. So far, I've only been able to make it clickable as a URL (not what I want, obvioiusly!)
Is there a way to do this on a really small, simple script for starters? I'm certain their is, but don't even know where to begin.
Any help appreciated
i have made a simple header page for a project.
now i want to create a dropdown menu for a single menu item in the menu bar.
how i will do that ..??
for ex-under COURSES MENU, THE SUBMENU ARE : DEGREE,DIPLOMA,HIGHSCHOOL.
Hi, I'm a little bit new to php and I'm having some issues selecting some data from a mySQL database and fetching it into a fluid html table..... Basicly what I want is a table with 4 columns and a X number of rows depending on how much entry is stored in the DB. Here's the SELECT code : Code: [Select] <?php mysql_connect("host", "user", "pass") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); $id = $_GET['id']; $data = mysql_query("SELECT * FROM artist_gallery WHERE artist_picid='$id'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { Here the part I just can't figure.... what I want is to fetch the x number of picture in the DB into a html table : Code: [Select] echo " <table border=\"1\" cellpadding=\"1\" cellspacing=\"0\"> <tr> <td><img src=\"".$info['picture']."\" border=\"0\" /></td> <td><img src=\"".$info['picture']."\" border=\"0\" /></td> <td><img src=\"".$info['picture']."\" border=\"0\" /></td> </tr> </table> "; } ?> The pictures are just repeating 3 times at each row... Any help will be greatly appreciated!!! Thanks! The code is posted he http://codepad.org/Fck5s2zz The attached file (delete_user.php) is the same as the code in the link above. The same code is also posted below. [text] What I am trying to do is create a function that will allow me to delete a user from my mysql database. I have an HTML select that outputs the username(s) using the function get_admin_username() (The function is posted below) There is also a HTML form I am using to make this happen. (Also posted below) In other words I would select the user I would like to delete, and click submit which will then delete the user from the database. The problem I am having is I do not know how to pass values from the HTML select, or the form, or even use the submit button value. I am not sure If I need to create a function to achieve this. Basically I don't know what to do this at all for that matter. I thought I might have gotten close but I thought wrong, and failed. I was told (in the php irc) that my method was way off and wrong but was given no help after that. I do have an example to show you of how I tried to accomplish this, but being told that I was wrong I did not feel that it was even worth posting it. I am lost and have been at this for two days now. I am a noobe but I do understand allot (I think). Someone, anyone, please help. Thank You, Ryan [/text] Code: Code: [Select] <?php // Session's Functions require_once("../includes/sessions/session.php"); // Establish A Connection To The Database require_once("../includes/connection/connection.php"); // User Defined Admin Functions require_once("includes/functions/admin_functions.php"); // New User Functions //require_once("includes/users/delete_user.php"); // Confirms If The User Is Logged In confirm_logged_in(); // Document Header include("includes/templates/default/header.php"); ?> <?php // Gets The Admin Username function get_admin_username() { global $connection; $query = "SELECT * FROM administration_users "; $query .= "ORDER BY username"; $admin_user_set = mysql_query($query, $connection); confirm_query($admin_user_set); while ($admin_users = mysql_fetch_array($admin_user_set)) { echo "<option value=\"username" . "\">" . $admin_users['username'] ."\n "; } } ?> <table id="structure"> <tr> <td id="navigation"> <a href="../staff.php">Return To Staff Menu</a> <a href="admin_content.php">Return To Admin Menu</a> <br /> <br /> <ul class="menu"> <li class="pages"><a id="page_menu" href="new_user.php">Add New User</a></li> <li class="pages"><a href="edit_user.php">Edit User</a></li> <li class="pages"><a href="list_users.php">List Users</a></li> <li class="pages"><a href="delete_user.php">Delete User</a></li> </ul> </td> <td id="page"> <h2>Remove User</h2> <br /> <form action="delete_user.php" name="delete_user" method="post"> <table> <tr> <th class="field_name field_padding_user_name">User Name: </th> <td> <select id="select_username" name="username_select"> <?php echo get_admin_username();?> </select> </td> </tr> <tr> <td class="delete_user_submit" colspan="2"><input type="submit" name="submit" value="Delete User" onclick="return confirm('Are You Sure You Want To Delete This User?');"/></td> </tr> </table> </form> </td> </tr> </table> <?php // Document Footer include("includes/templates/default/footer.php"); ?> MOD EDIT: [code] . . . [/code] tags added. I have a test database, I have two names in the database which get returned just fine in my html dropdown. I am trying to figure out how to figure out which item in the list was selected so that I can return information from another table based on the selected id. This is what I am trying now but I don't know how to proceed or if it is correct Code: [Select] $result = $mysql->query("SELECT * FROM names") or die($mysql->error); ?> <select> <?php if($result){ while($row = $result->fetch_object()){ $id = $row->nameID; $name = $row->firstName . " " . $row->lastName; ?> <option value"<?php $id ?>"><?php echo $name ?></option> <?php }?> </select> <?php } ?> Here's a question for all you great php programmers. What I want to do is use a variable username as the name of a select input of a form. I.E echo"<select name='$user'>"; Of course this code doesn't work though I feel sure that there must be a way to do this. Anyone know it? I have a form with dropdown list that is populated with values from Sql Server table. Now i would like to use this selected item in SQL query. The results of this query should be shown in label or text field. So when a user selects item from dropdown menu, results from SQL query are shown at the same time. I have two dropdown list at the moment in my form. First one gets all values from a column in table in SQL Server. And the second one should get a value from the same table based on a selection in first dropdown list.
When i load ajax.php i get 2 error mesages: This is my code so far. I have tried to do it with this Ajax script. But i can only get first dropdown to work. The second dropdown(sub_machinery) does not show values, when first dropdown item is selected. The second dropdown should show values from databse table with this query( *$machineryID* is first dropdown selected item): SELECT MachineID FROM T013 WHERE Machinery=".$machineryID. Index.php <!doctype html> <?PHP $server = "server"; $options = array( "UID" => "user", "PWD" => "pass", "Database" => "database"); $conn2 = sqlsrv_connect($server, $options); if ($conn2 === false) die("<pre>".print_r(sqlsrv_errors(), true)); echo " "; ?> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <section id="formaT2" class="formaT2 formContent"> <div class="row"> <div class="col-md-2 col-3 row-color remove-mob"></div> <div class="col-md-5 col-9 bg-img" style="padding-left: 0; padding-right: 0;"> <h1>Form</h1> <div class="rest-text"> <div class="contactFrm"> <p class="statusMsg <?php echo !empty($msgClass)?$msgClass:''; ?>"><?php echo $statusMsg; ?></p> <form action="connection.php" method="post"> <div>machinery</div> <select id="machinery"> <option value="0">--Please Select Machinery--</option> <?php // Fetch Department $sql = "SELECT Machinery FROM T013"; $machanery_data = sqlsrv_query($conn2,$sql); while($row = sqlsrv_fetch_array($machanery_data) ){ $id = $row['Id']; $machinery = $row['Machinery']; // Option echo "<option value='".$id."' >".$machinery."</option>"; } ?> </select> <div class="clear"></div> <div>Sub Machinery</div> <select id="sub_machinery"> <option value="0">- Select -</option> </select> <input type="submit" name="submit" id="submit" class="strelka-send" value="Insert"> <div class="clear"> </div> </form> </div> </div> </div> </div> </section> </script> <script type="text/javascript"> $(document).ready(function(){ $("#machinery").change(function(){ var machinery_id = $(this).val(); $.ajax({ url:'ajaxfile.php', type: 'post', data: {machinery:machinery_id}, dataType: 'json', success:function(response){ var len = response.length; $("#sub_machinery").empty(); for( var i = 0; i<len; i++){ var machinery_id = response[i]['machinery_id']; var machinery = response[i]['machinery']; $("#sub_machinery").append("<option value='"+machinery_id+"'>"+machinery+"</option>"); } } }); }); }); </script> </body> </html> Ajaxfile.php <?php $server = "server"; $options = array( "UID" => "user", "PWD" => "pass", "Database" => "database"); $conn2 = sqlsrv_connect($server, $options); if ($conn2 === false) die("<pre>".print_r(sqlsrv_errors(), true)); echo " "; $machineryID = $_POST['machinery']; // department id $sql = "SELECT MachineID FROM T013 WHERE Machinery=".$machineryID; $result = sqlsrv_query($conn2,$sql); $machinery_arr = array(); while( $row = sqlsrv_fetch_array($result) ){ $machinery_id = $row['ID']; $machinery = $row['MachineID']; $machinery_arr[] = array("ID" => $machinery_id, "MachineID" => $machinery); } // encoding array to json format echo json_encode($machinery_arr); ?>Edited May 6, 2019 by davidd |