PHP - Posting Selected Drop Down Value
Hey
how would I post the selected value from the following code? Quote $sql="SELECT username FROM members"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $username=$row["username"]; $options.="<OPTION VALUE=\"$id\">".$username; } ?> <SELECT NAME="person"> <OPTION VALUE=0>Choose <?=$options?> </SELECT> Similar TutorialsOk, I have one database three tables. Table 1 is ncmr the main table where everything is to be entered. Table 2 is companies, where all the companies in pull down menu 1 is located. Table 3 is fabricators, where all the people who have had hands on the product are residing. I want the selected choices of table 2 and 3 to be inputed into table 1. I know this has to be possible, but I don't know how. I thought I wrote the code correctly, but it seems not. Can someone review my code and show me where my mistake is? Here is the page: http://kaboomlabs.com/PDI/post2.php Thanks. Code: [Select] <?php require_once('connectvars.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>PDI Non-Conforming Materials Report</title> <link rel="stylesheet" type="text/css" href="CSS/postie.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <div id="title"> <h3 id="NCMR2">Non-Conforming Materials Report (NCMR)</h3> </div> <?php //Post Data if (isset($_POST['submit'])) { $ab = mysqli_real_escape_string($dbc,$_POST['ab']); $date = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime ($_POST['date']))); $part = mysqli_real_escape_string($dbc,$_POST['part']); $rev = mysqli_real_escape_string($dbc,$_POST['rev']); $partdesc = mysqli_real_escape_string($dbc,$_POST['partdesc']); $ncmrqty = mysqli_real_escape_string($dbc,$_POST['ncmrqty']); $comp = mysqli_real_escape_string($dbc,$_POST['comp']); $ncmrid = mysqli_real_escape_string($dbc,$_POST['ncmrid']); $rma = mysqli_real_escape_string($dbc,$_POST['rma']); $jno = mysqli_real_escape_string($dbc,$_POST['jno']); $fdt = mysqli_real_escape_string($dbc,$_POST['fdt']); $cof = mysqli_real_escape_string($dbc,$_POST['cof']); $fab1= mysqli_real_escape_string($dbc,$_POST['fab1']); $fab2= mysqli_real_escape_string($dbc,$_POST['fab2']); $fab3= mysqli_real_escape_string($dbc,$_POST['fab3']); $non= mysqli_real_escape_string($dbc,$_POST['non']); $dis= mysqli_real_escape_string($dbc,$_POST['dis']); $comm= mysqli_real_escape_string($dbc,$_POST['comm']); $caad= mysqli_real_escape_string($dbc,$_POST['caad']); $po= mysqli_real_escape_string($dbc,$_POST['po']); $pod = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime($_POST['pod']))); $dri = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime($_POST['dri']))); $output_form = 'no'; if (empty($ab) || empty($date) || empty($part) || empty($partdesc)){ // We know at least one of the input fields is blank echo '<div id="alert">'; echo 'Please fill out all of the required NCMR information.<br />'; echo '</div>'; } $output_form = 'yes'; } //Access the Database if (!empty($ab) && !empty($date) && !empty($pod)) { $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); $query = "INSERT INTO ncmr (ab, date, part, rev, partdesc, ncmrqty, comp, ncmrid, rma, jno, fdt, cof, fab1, fab2, fab3, non, dis, comm, caad, po, pod, dri) VALUES ('$ab','$date','$part','$rev','$partdesc','$ncmrqty','$comp','$ncmrid','$rma','$jno','$fdt','$cof','$fab1','$fab2','$fab3','$non','$dis','$comm','$caad','$po','$pod','$dri')"; $data = mysqli_query($dbc, $query) or die("MySQL error: " . mysqli_error($dbc) . "<hr>\nQuery: $query"); // Confirm success with the user echo '<tr><td class="thank">'; echo '<p>Thank you for adding the NCRM, the correct person will be informed.</p>'; echo '<p><a href="post.php"><< Back to the form</a></p>'; $output_form = 'no'; echo '</td></tr>'; mysqli_close($dbc); } if ($output_form == 'yes') { echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>"; echo '<fieldset>'; //Part, Rev, Part Description, NCMR Qty echo '<div id="box1">'; echo '<div id="ab"><span class="b">Added By: </span><input type="text" name="ab" value="" /></div>'; echo '<div id="date"><span class="b">Date Filed: </span><input type="text" name="date" value="" /></div>'; echo '<div id="part"><span class="b">Part Number: </span><input type="text" name="part" value="" /></div>'; echo '<div id="rev"><span class="b">Part Revision: </span><input type="text" name="rev" value="" /></div>'; echo '<div id="partdesc"><span class="b">Part Description: </span><textarea name="partdesc" rows="3" cols="22" ></textarea></div>'; echo '<div id="ncmrqty"><span class="b">NCMR Qty: </span><input type="text" name="ncmrqty" value="" /></div>'; echo '</div>'; //Company, Customer NCMR, Internal RMA, and Job Number echo '<div id="box2">'; echo'<div id="comp">'; echo '<span class="b">Company: </span>'; $mysqli->select_db('comp'); $result = $mysqli->query("SELECT * FROM comp"); $i = 0; echo "<SELECT name='comp'>\n"; while($row = $result->fetch_assoc()) { if ($i == 4) echo '<option value="lines">-----</option>'; echo "<option value='{$row['user_id']}'>{$row['name']}</option>\n"; $i++; } echo "</select>\n"; echo '</div>'; echo '<div id="ncmrid"><span class="b">Customer NCMR ID: </span><input type="text" name="ncmrid" value="" /></div>'; echo '<div id="rma"><span class="b">Internal RMA #: </span><input type="text" name="rma" value="" /></div>'; echo '<div id="jno"><span class="b">Job #: </span><input type="text" name="jno" value="" /></div>'; echo '</div>'; //Type of Failure and Class of Failure echo '<div id="box3">'; echo '<h2>Failure</h2>'; echo '<div id="fdt">'; echo '<span class="b">Failure Due To: </span><br />'; echo '<select name="fdt">'; echo '<option value="none">----None----</option>'; echo '<option value="In House">In House</option>'; echo '<option value="Third Party">Third Party</option>'; echo '</select>'; echo '</div>'; echo'<div id="cof">'; echo '<span class="b">Class of Failu </span><br />'; echo '<select name="cof">'; echo '<option value="none">----None----</option>'; echo '<option value="Materials">Materials</option>'; echo '<option value="Fabrication">Fabrication</option>'; echo '<option value="Drawing">Drawing</option>'; echo '<option value="Assembly">Assembly</option>'; echo '<option value="Testing">Testing</option>'; echo '<option value="Electrical">Electrical</option>'; echo '<option value="Programming">Programming</option>'; echo '<option value="Machining">Machining</option>'; echo '<option value="Inspection">Inspection</option>'; echo '<option value="Purchasing">Purchasing</option>'; echo '<option value="Administrator">Administrator</option>'; echo '</select>'; echo '</div>'; echo '</div>'; //Fabricators echo '<div id="box4">'; echo '<h2>Fabricators</h2>'; echo'<div id="fab1">'; $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab1'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";} echo "</select>\n"; echo '</div>'; echo'<div id="fab2">'; $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab2'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";} echo "</select>\n"; echo '</div>'; echo'<div id="fab3">'; $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab3'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";} echo "</select>\n"; echo '</div>'; echo '</div>'; //Nonconformity, Disposition, Comments and Comments & Additional Details echo '<div id="box5">'; echo '<div id="non"><span class="b">Nonconformity: </span><br /><textarea name="non" rows="3" cols="110" ></textarea><br /></div>'; echo '<div id="dis"><span class="b">Disposition: </span><br /><textarea name="dis" rows="3" cols="110" ></textarea></div>'; echo '<div id="comm"><span class="b">Comments: </span><br /><textarea name="comm" rows="3" cols="110" ></textarea></div>'; echo '<div id="caad"><span class="b">Comments and/or Additional Details: </span><br /><textarea name="caad" rows="3" cols="110" ></textarea></div>'; //PO, PO Date, and Date Recieved echo '<div id="podr">'; echo '<div id="po"><span class="b">PO: </span><input type="text" name="po" size="7" value="" /></div>'; echo '<div id="pod"><span class="b">PO Date: </span><input type="text" name="pod" size="7" value="" /></div>'; echo '<div id="dri"><span class="b">Date Received: </span><input type="text" name="dri" size="7" value=""'; echo '</div>'; echo '<div id="button"><input type="submit" value="Submit NCMR" name="submit" /></div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } ?> </body> </html> Hi all !
I wish to post the value of an auto submit dropdown value to another page, be redirected to that page, and use it on that page. I am unable to achieve this in php and so I tried as :-follows:-
dropdown.php
<form method="post" action = dropdownaction.php> <select name="myselect" onchange="this.form.submit();"> <option>blue</option> <option>red</option> </select> </form>and now I need the equivalent of dropdownaction.php <?php if(isset($_POST(['myselect']))) echo " I am selected".$_POST['myselect']; ?>Please can someone tell me how I may retrieve the value of 'myselect' in the dropdownaction.php after being redirected to it. Thanks loads. Hey guys, im trying to make a dropdown box get a selected value based on the value from multiple rows. Here is what im trying to do: <?php // select the value from the database // $value = ... ?> <form action="..."> <option value="1"<?php if ($value == 1) { echo ' selected="selected"'; } ?>>First</option> <option value="2"<?php if ($value == 2) { echo ' selected="selected"'; } ?>>Seccond</option> <option value="3"<?php if ($value == 3) { echo ' selected="selected"'; } ?>>Third</option> <input type="submit"> </form> The thing is I have no idea what to put at the top and how to assign the $value part. Here is my current code. <?php mysql_connect("localhost", "", "")or die("cannot connect"); mysql_select_db("test")or die("cannot select DB"); $tbl_name="test_mysql"; $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); // MOVED this code to the top before you output anything if (isset($_POST['Submit'])) { for($i=0;$i<$count;$i++){ $month = $_POST['month']; $date = $_POST['date']; $message = $_POST['message']; $title = $_POST['title']; $id = $_POST['id']; $icon = $_POST['icon']; // ILYA $monthday= $month[$i]."<br>".$date[$i]; $sql1="UPDATE $tbl_name SET monthday='$monthday', month='$month[$i]', date='$date[$i]', message='" . mysql_real_escape_string($message[$i]) . "', title='" . mysql_real_escape_string($title[$i]) . "', icon='$icon[$i]' WHERE id=".$id[$i]; // ILYA if(!($result1 = mysql_query($sql1))){ "<BR>Error UPDATING $tbl_name "; exit(); } } } $result=mysql_query($sql); $count=mysql_num_rows($result); ?> Here is the selection dropdown box im trying to make work: <select name="icon[]" style="display:blolck; width:200px" class="mydds"> <option value="1" title="icon/icon_phone.gif">Phone</option> <option value="2" title="icon/icon_sales.gif">Graph</option> <option value="3" title="icon/icon_faq.gif">Faq</option> </select> The thing is, it gets multiple rows at once and I want to make it select each one differently based on the rows value. I dont want it to like interfere. Do you kinda know what I mean? Also, heres hows the database looks like. Picture of webpage. Here is the full code if anyone would like to see: <?php mysql_connect("localhost", "", "")or die("cannot connect"); mysql_select_db("test")or die("cannot select DB"); $tbl_name="test_mysql"; $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); // MOVED this code to the top before you output anything if (isset($_POST['Submit'])) { for($i=0;$i<$count;$i++){ $month = $_POST['month']; $date = $_POST['date']; $message = $_POST['message']; $title = $_POST['title']; $id = $_POST['id']; $icon = $_POST['icon']; // ILYA $monthday= $month[$i]."<br>".$date[$i]; $sql1="UPDATE $tbl_name SET monthday='$monthday', month='$month[$i]', date='$date[$i]', message='" . mysql_real_escape_string($message[$i]) . "', title='" . mysql_real_escape_string($title[$i]) . "', icon='$icon[$i]' WHERE id=".$id[$i]; // ILYA if(!($result1 = mysql_query($sql1))){ "<BR>Error UPDATING $tbl_name "; exit(); } } } $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <!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>Image Dropdown</title> <link rel="stylesheet" type="text/css" href="dd.css" /> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <script type="text/javascript" src="jquery.dd.js"></script> </head> <body> <form name="form1" method="post" action="updat5.php"><!--ILYA--> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>ID</strong></td> <td align="center"><strong>Month - Date</strong></td> <td align="center"><strong>Message</strong></td> <td align="center"><strong>Title</strong></td> <td align="center"><strong>Icon</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><input style="border: 1px solid #C3C3C3;height: 20px; width: 20px;" id="id" name="id[]" value="<?php echo $rows['id']; ?>"></td> <td align="center"><input style="border: 1px solid #C3C3C3;height: 20px;" name="month[]" MAXLENGTH="3" size="3" type="text" id="month" value="<?php echo $rows['month']; ?>"> <input style="border: 1px solid #C3C3C3;height: 20px;" name="date[]" MAXLENGTH="2" size="2" type="text" id="date" value="<?php echo $rows['date']; ?>"> </td> <td align="center"><input style="border: 1px solid #C3C3C3;height: 20px;" name="message[]" size="70" type="text" id="message" value="<?php echo $rows['message']; ?>"></td> <td align="center"><input style="border: 1px solid #C3C3C3;height: 20px;" name="title[]" size="70" type="text" id="title" value="<?php echo $rows['title']; ?>"></td> <td align="center"> <select name="icon[]" style="display:blolck; width:200px" class="mydds"> <option value="1" title="icon/icon_phone.gif">Phone</option> <option value="2" title="icon/icon_sales.gif">Graph</option> <option value="3" title="icon/icon_faq.gif">Faq</option> </select> </td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><br><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> <script language="javascript" type="text/javascript"> function showvalue(arg) { alert(arg); //arg.visible(false); } $(document).ready(function() { try { oHandler = $(".mydds").msDropDown().data("dd"); oHandler.visible(true); //alert($.msDropDown.version); //$.msDropDown.create("body select"); $("#ver").html($.msDropDown.version); } catch(e) { alert("Error: "+e.message); } }) </script> </body> </html> Hi all I am trying to create a menu that shows the initially selected value depending on which page the user is on: <?php $fetchcategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($returnedcategories=mysql_fetch_array($fetchcategories)) { echo "<option value=\"".$returnedcategories['name']."\" selected=\"selected\" >".$returnedcategories['name']."</option>"; } ?> There are three product categories; Stone, Wood and Accessories. in the SQL. When on the stone.php page I need the option value 'stone' to stay selected. Many thanks for your help Pete 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> I've got a HTML drop down box as similar to this: <select name="dropdown"> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> If I run a mysql query and get a result of "Option 3", is there anyway using PHP to give Option 3 the selected value? Hi, A quick question please , I am trying to assign a selected index to a drop down list based on data retrieved from the database. I tried using JavaScript : document.getElementById('Country').selectedIndex ='".$array['Country']."'; but it does work. Any suggestion? Hi all I am trying to get my drop down menu to use a session variable as the selected menu option. Here's my code: echo "<option value=\"\">Delivery Area</option>"; $selected = ""; if(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "England") { $selected = "selected"; } elseif(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "Wales") { $selected = "selected"; } elseif(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "Scotland") { $selected = "selected"; } else { $selected = ""; } echo " <option value=\"England\" selected=\"".$selected."\">England</option>"; echo "<option value=\"Scotland\" selected=\"".$selected."\">Scotland</option>"; echo "<option value=\"Wales\" selected=\"".$selected."\">Wales</option>"; echo "</select>"; However, this shows the 'Wales' one all the? Please help! Many thanks Pete Hi all,
I am trying to validate all required fields in my contact form using php. However I am unable to retain what was selected in my country dropdown list after it is selected and submitted if the form had errror while validating. I want the form to retain the value that was selected by the user to stay in the form so that users can make necessary changes and resubmit the form all other values stay in the form except the country dropdown. Please help Below is the code. <!DOCTYPE HTML> <html> <head> <style> .error {color: #FF0000;} </style> </head> <body> <?php // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = $countryErr = ""; $name = $email = $gender = $comment = $website = ""; $country =""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address syntax is valid if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { $emailErr = "Invalid email format"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // check if URL address syntax is valid (this regular expression also allows dashes in the URL) if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "Invalid URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["gender"])) { $genderErr = "Gender is required"; } else { $gender = test_input($_POST["gender"]); } $country = $_POST['country']; if (!in_array($country, array("AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "Gg", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "SH", "KN", "LC", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "CS", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "GS", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW" ))) { $country1 = "Please select your country";} } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>contact us</h2> <p><span class="error">* required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br> <legend>Country:</legend> <select name="country"> <option value="NULL">select</option> <option value="AF">Afghanistan</option> <option value="AX">Ã…Land Islands</option> <option value="AL">Albania</option> <option value="DZ">Algeria</option> <option value="AS">American Samoa</option> <option value="AD">Andorra</option> <option value="AO">Angola</option> <option value="AI">Anguilla</option> <option value="AQ">Antarctica</option> <option value="AG">Antigua And Barbuda</option> <option value="AR">Argentina</option> <option value="AM">Armenia</option> <option value="AW">Aruba</option> <option value="AU">Australia</option> <option value="AT">Austria</option> <option value="AZ">Azerbaijan</option> <option value="BS">Bahamas</option> <option value="BH">Bahrain</option> <option value="BD">Bangladesh</option> <option value="BB">Barbados</option> <option value="BY">Belarus</option> <option value="BE">Belgium</option> <option value="BZ">Belize</option> <option value="BJ">Benin</option> <option value="BM">Bermuda</option> <option value="BT">Bhutan</option> <option value="BO">Bolivia</option> <option value="BA">Bosnia And Herzegovina</option> <option value="BW">Botswana</option> <option value="BV">Bouvet Island</option> <option value="BR">Brazil</option> <option value="IO">British Indian Ocean Territory</option> <option value="BN">Brunei Darussalam</option> <option value="BG">Bulgaria</option> <option value="BF">Burkina Faso</option> <option value="BI">Burundi</option> <option value="KH">Cambodia</option> <option value="CM">Cameroon</option> <option value="CA">Canada</option> <option value="CV">Cape Verde</option> <option value="KY">Cayman Islands</option> <option value="CF">Central African Republic</option> <option value="TD">Chad</option> <option value="CL">Chile</option> <option value="CN">China</option> <option value="CX">Christmas Island</option> <option value="CC">Cocos (Keeling) Islands</option> <option value="CO">Colombia</option> <option value="KM">Comoros</option> <option value="CG">Congo</option> <option value="CD">Congo, The Democratic Republic Of The</option> <option value="CK">Cook Islands</option> <option value="CR">Costa Rica</option> <option value="CI">Cote D'Ivoire</option> <option value="HR">Croatia</option> <option value="CU">Cuba</option> <option value="CY">Cyprus</option> <option value="CZ">Czech Republic</option> <option value="DK">Denmark</option> <option value="DJ">Djibouti</option> <option value="DM">Dominica</option> <option value="DO">Dominican Republic</option> <option value="EC">Ecuador</option> <option value="EG">Egypt</option> <option value="SV">El Salvador</option> <option value="GQ">Equatorial Guinea</option> <option value="ER">Eritrea</option> <option value="EE">Estonia</option> <option value="ET">Ethiopia</option> <option value="FK">Falkland Islands (Malvinas)</option> <option value="FO">Faroe Islands</option> <option value="FJ">Fiji</option> <option value="FI">Finland</option> <option value="FR">France</option> <option value="GF">French Guiana</option> <option value="PF">French Polynesia</option> <option value="TF">French Southern Territories</option> <option value="GA">Gabon</option> <option value="GM">Gambia</option> <option value="GE">Georgia</option> <option value="DE">Germany</option> <option value="GH">Ghana</option> <option value="GI">Gibraltar</option> <option value="GR">Greece</option> <option value="GL">Greenland</option> <option value="GD">Grenada</option> <option value="GP">Guadeloupe</option> <option value="GU">Guam</option> <option value="GT">Guatemala</option> <option value="Gg">Guernsey</option> <option value="GN">Guinea</option> <option value="GW">Guinea-Bissau</option> <option value="GY">Guyana</option> <option value="HT">Haiti</option> <option value="HM">Heard Island And Mcdonald Islands</option> <option value="VA">Holy See (Vatican City State)</option> <option value="HN">Honduras</option> <option value="HK">Hong Kong</option> <option value="HU">Hungary</option> <option value="IS">Iceland</option> <option value="IN">India</option> <option value="ID">Indonesia</option> <option value="IR">Iran, Islamic Republic Of</option> <option value="IQ">Iraq</option> <option value="IE">Ireland</option> <option value="IM">Isle Of Man</option> <option value="IL">Israel</option> <option value="IT">Italy</option> <option value="JM">Jamaica</option> <option value="JP">Japan</option> <option value="JE">Jersey</option> <option value="JO">Jordan</option> <option value="KZ">Kazakhstan</option> <option value="KE">Kenya</option> <option value="KI">Kiribati</option> <option value="KP">Korea, Democratic People'S Republic Of</option> <option value="KR">Korea, Republic Of</option> <option value="KW">Kuwait</option> <option value="KG">Kyrgyzstan</option> <option value="LA">Lao People'S Democratic Republic</option> <option value="LV">Latvia</option> <option value="LB">Lebanon</option> <option value="LS">Lesotho</option> <option value="LR">Liberia</option> <option value="LY">Libyan Arab Jamahiriya</option> <option value="LI">Liechtenstein</option> <option value="LT">Lithuania</option> <option value="LU">Luxembourg</option> <option value="MO">Macao</option> <option value="MK">Macedonia, The Former Yugoslav Republic Of</option> <option value="MG">Madagascar</option> <option value="MW">Malawi</option> <option value="MY">Malaysia</option> <option value="MV">Maldives</option> <option value="ML">Mali</option> <option value="MT">Malta</option> <option value="MH">Marshall Islands</option> <option value="MQ">Martinique</option> <option value="MR">Mauritania</option> <option value="MU">Mauritius</option> <option value="YT">Mayotte</option> <option value="MX">Mexico</option> <option value="FM">Micronesia, Federated States Of</option> <option value="MD">Moldova, Republic Of</option> <option value="MC">Monaco</option> <option value="MN">Mongolia</option> <option value="MS">Montserrat</option> <option value="MA">Morocco</option> <option value="MZ">Mozambique</option> <option value="MM">Myanmar</option> <option value="NA">Namibia</option> <option value="NR">Nauru</option> <option value="NP">Nepal</option> <option value="NL">Netherlands</option> <option value="AN">Netherlands Antilles</option> <option value="NC">New Caledonia</option> <option value="NZ">New Zealand</option> <option value="NI">Nicaragua</option> <option value="NE">Niger</option> <option value="NG">Nigeria</option> <option value="NU">Niue</option> <option value="NF">Norfolk Island</option> <option value="MP">Northern Mariana Islands</option> <option value="NO">Norway</option> <option value="OM">Oman</option> <option value="PK">Pakistan</option> <option value="PW">Palau</option> <option value="PS">Palestinian Territory, Occupied</option> <option value="PA">Panama</option> <option value="PG">Papua New Guinea</option> <option value="PY">Paraguay</option> <option value="PE">Peru</option> <option value="PH">Philippines</option> <option value="PN">Pitcairn</option> <option value="PL">Poland</option> <option value="PT">Portugal</option> <option value="PR">Puerto Rico</option> <option value="QA">Qatar</option> <option value="RE">Reunion</option> <option value="RO">Romania</option> <option value="RU">Russian Federation</option> <option value="RW">Rwanda</option> <option value="SH">Saint Helena</option> <option value="KN">Saint Kitts And Nevis</option> <option value="LC">Saint Lucia</option> <option value="PM">Saint Pierre And Miquelon</option> <option value="VC">Saint Vincent And The Grenadines</option> <option value="WS">Samoa</option> <option value="SM">San Marino</option> <option value="ST">Sao Tome And Principe</option> <option value="SA">Saudi Arabia</option> <option value="SN">Senegal</option> <option value="CS">Serbia And Montenegro</option> <option value="SC">Seychelles</option> <option value="SL">Sierra Leone</option> <option value="SG">Singapore</option> <option value="SK">Slovakia</option> <option value="SI">Slovenia</option> <option value="SB">Solomon Islands</option> <option value="SO">Somalia</option> <option value="ZA">South Africa</option> <option value="GS">South Georgia And The South Sandwich Islands</option> <option value="ES">Spain</option> <option value="LK">Sri Lanka</option> <option value="SD">Sudan</option> <option value="SR">Suriname</option> <option value="SJ">Svalbard And Jan Mayen</option> <option value="SZ">Swaziland</option> <option value="SE">Sweden</option> <option value="CH">Switzerland</option> <option value="SY">Syrian Arab Republic</option> <option value="TW">Taiwan, Province Of China</option> <option value="TJ">Tajikistan</option> <option value="TZ">Tanzania, United Republic Of</option> <option value="TH">Thailand</option> <option value="TL">Timor-Leste</option> <option value="TG">Togo</option> <option value="TK">Tokelau</option> <option value="TO">Tonga</option> <option value="TT">Trinidad And Tobago</option> <option value="TN">Tunisia</option> <option value="TR">Turkey</option> <option value="TM">Turkmenistan</option> <option value="TC">Turks And Caicos Islands</option> <option value="TV">Tuvalu</option> <option value="UG">Uganda</option> <option value="UA">Ukraine</option> <option value="AE">United Arab Emirates</option> <option value="GB">United Kingdom</option> <option value="US">United States</option> <option value="UM">United States Minor Outlying Islands</option> <option value="UY">Uruguay</option> <option value="UZ">Uzbekistan</option> <option value="VU">Vanuatu</option> <option value="VE">Venezuela</option> <option value="VN">Viet Nam</option> <option value="VG">Virgin Islands, British</option> <option value="VI">Virgin Islands, U.S.</option> <option value="WF">Wallis And Futuna</option> <option value="EH">Western Sahara</option> <option value="YE">Yemen</option> <option value="ZM">Zambia</option> <option value="ZW">Zimbabwe</option> </select> <span class="error">*<?php echo $country1;?></span> <br><br> Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr;?></span> <br><br> Gender: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr;?></span> <br><br> Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br><br> <input type="submit" name="submit" value="Submit"> </form> </body> </html> Edited by Ch0cu3r, 15 July 2014 - 03:37 PM. Reformatted post Hi all I need to combine these two scripts: Firstly, the following decides which out of the following list is selected based on its value in the mySQL table: <select name="pack_choice"> <option value="Meters / Pack"<?php echo (($result['pack_choice']=="Meters / Pack") ? ' selected="selected"':'') ?>>Meters / Pack (m2)</option> <option value="m3"<?php echo (($result['pack_choice']=="m3") ? ' selected="selected"':'') ?>>Meters / Pack (m3)</option> <option value="Quantity"<?php echo (($result['pack_choice']=="Quantity") ? ' selected="selected"':'') ?>>Quantity</option> </select> Although this works OK, I need it also to show dynamic values like this: select name="category"> <?php $listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($categoryReturned=mysql_fetch_array($listCategories)) { echo "<option value=\"".$categoryReturned['name']."\">".$categoryReturned['name']."</option>"; } ?> </select> I'm not sure if this is possible? Many thanks for your help. Pete Hey can anyone please help? I making this form on my website and I have two drop down lists, one is for sizes and the other is for colors. They both have an option for "other" and I'm wanting a textbox to appear when "other" is selected. I got the first drop down to work but I can't figure out how to get the second one to work without messing with the first. Here is the code I have please help: <form name="form1" method="post" action=""> <script type="text/javascript"> function showfield(name){ if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />'; else document.getElementById('div1').innerHTML=''; } </script> <p>Size: <select name="size" id="size" onchange="showfield(this.options[this.selectedIndex].value)"> <option selected="selected">Please select ...</option> <option value="1' H X 6" W">2' H X 1' 6" W</option> <option value="1' H X 2' W">1' H X 2' W</option> <option value="1' H X 1' 4" W">1' H X 1' 4" W</option> <option value="Other">Other</option> </select> <div id="div1"></div> <p>Color: <select name="Color" id="Color" onchange="showfield(this.options[this.selectedIndex].value)"> <option selected="selected">Please select ...</option> <option value="Walnut Stain/Dark Brown">Walnut Stain/Dark Brown</option> <option value="Tan">Tan</option> <option value="Walnut">Walnut</option> <option value="Other">Other</option> </select> <div id="div1"></div> </p> I have this loop on a shorturl website i own that selects domains from my website and lists them in a dropdown list where users can select one domain to use as url shortener. The problem is that when a users selects and entry from the dropdown list this created only the [[[main_url]]] entry from the database table bellow can be used. When someone selectes "coolartistname.site.com the submit button cannot be pressed. in other words it's not adding the SELECTED attribute other than the [[[main_url]]] domain. Can anyone see on the code bellow why this would happen?
**Index.php** // get base urls $shortUrlDomains = getShortUrlDomains(); <?php foreach ($shortUrlDomains AS $k => $shortUrlDomain) { // active domains only if (($shortUrlDomain['premium_only'] !== '1') && ($shortUrlDomain['premium_only'] !== $Auth->id)) { continue; } echo '<option value="' . (int)$k . '"'; if (isset($_REQUEST['shortUrlDomain'])) { if ($k == (int)$_REQUEST['shortUrlDomain']) { echo 'SELECTED'; } } echo '>'; echo $shortUrlDomain['domain']; if ($disabled == true) { echo ' (' . safeOutputToScreen(t('unavailable', 'unavailable')) . ')'; } '</option>'; } echo '</optgroup>'; ?> FUNCTIONS.PHP function getShortUrlDomains() { // if we already have it cached if(defined('_SETTINGS_SHORT_URL_DOMAINS')) { return unserialize(_SETTINGS_SHORT_URL_DOMAINS); } // get connection $db = Database::getDatabase(true); // load from database $domains = $db->getRows("SELECT id, domain, premium_only, status FROM url_domain ORDER BY premium_only ASC, id ASC"); // organise and replace site url $rs = array(); foreach($domains AS $domain) { if($domain['domain'] == '[[[main_url]]]') { $domain['domain'] = _CONFIG_SITE_FULL_URL; } $rs[$domain{'id'}] = $domain; } **MYSQL DATABASE** url_domain (id, domain, premium_only, status, date_created, owner) VALUES (1, '[[[main_url]]]', 0, 'enabled', '2019-03-02 08:13:00', 1) (14, 'coolartistname.site.com', 6, 'enabled', '2020-04-18 19:21:59', 6);
Hi all, I have a html drop down menu and want to show the initially selected value as the one stored in the mysql database that a member selected. I have 180+ rows in mysql that a member could have selected and would like to basically do this: IF (value of option == $row['value'] ) { echo "selected=\"selected\"; } I could put this in every one of the rows it would be much better to have an if statement. As there are so many values I do not know where to begin. Can someone point me in the right direction? Thanks i'm doing a form that posts values to XML, and i don't know how. can someone help me with a quick lesson in passing variables/XML data? i don't even know what question to ask, actually - the XML format i've been given is: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <lead> <innerNode></innerNode> <last_name>Smith</last_name> <first_name>John</first_name> </lead> and what i've come up with so far is this, but i don't even know if i'm on the right track: Code: [Select] $last_name = $_REQUEST['l_name']; $first_name = $_REQUEST['f_name']; $url = "http://url.com/leads"; $post_string = '<?xml version="1.0" encoding="UTF-8"?> <lead> <innerNode></innerNode> <last_name>'.$last_name.'</last_name> <first_name>'.$first_name.'</first_name> </lead>'; $header = "POST HTTP/1.0 \r\n"; $header .= "Content-type: text/xml \r\n"; $header .= "Content-length: ".strlen($post_string)." \r\n"; $header .= "Content-transfer-encoding: text \r\n"; $header .= "Connection: close \r\n\r\n"; $header = $post_string; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); $data = curl_exec($ch); if(curl_errno($ch)) { print curl_error($ch); } else { echo "yay"; curl_close($ch); } i'm being told "should return a response.xml with either a success or failure post status." which is confusing me can someone help a bit? thanks very much... GN Hi guys, I have a list box. say the code is Code: [Select] <select name="drop1" id="Select1" size="4" multiple="multiple"> <option value="1">item 1</option> <option value="2">item 2</option> <option value="3">item 3</option> <option value="4">item 4</option> <option value="0">All</option> </select> The user will select few items. How do i capture the data through the "POST" method. Code: [Select] $data = $_POST['drop']; would not work coz there is an array if data. Can any one help or point me in the right direction? Thanks in advance You guys helped me create a function to gather information for my database. Now I need some help with posting that information. Function code and Form: <?php include("opendatabase.php"); ?> <?php function createMatchup($week, $game) { $query1 = "SELECT team_name FROM schedule, teams WHERE schedule.week_id = $week AND schedule.game_id = $game AND schedule.A_team = teams.team_id"; $query2 = "SELECT team_name FROM schedule, teams WHERE schedule.week_id = $week AND schedule.game_id = $game AND schedule.H_team = teams.team_id"; $result1 = mysql_fetch_assoc(mysql_query($query1)); $result2 = mysql_fetch_assoc(mysql_query($query2)); $output = " <input type=\"text\" size = \"3\" name=\"w$weekg$gameA\"> {$result1['team_name']} vs. {$result2['team_name']} <input type=\"text\" size = \"3\" name=\"w$weekg$gameH\">"; return $output; } $game1 = createMatchup(1, 1); $game2 = createMatchup(1, 2); $game3 = createMatchup(1, 3); $game4 = createMatchup(1, 4); $game5 = createMatchup(1, 5); $game6 = createMatchup(1, 6); $game7 = createMatchup(1, 7); $game8 = createMatchup(1, 8); $game9 = createMatchup(1, 9); $game10 = createMatchup(1, 10); $game11 = createMatchup(1, 11); $game12 = createMatchup(1, 12); $game13 = createMatchup(1, 13); $game14 = createMatchup(1, 14); $game15 = createMatchup(1, 15); $game16 = createMatchup(1, 16); mysql_close($con); ?> <form action="insert_spreads.php" method="post"> <?php echo $game1; ?> <br> <?php echo $game2; ?> <br> <?php echo $game3; ?> <br> <?php echo $game4; ?> <br> <?php echo $game5; ?> <br> <?php echo $game6; ?> <br> <?php echo $game7; ?> <br> <?php echo $game8; ?> <br> <?php echo $game9; ?> <br> <?php echo $game10; ?> <br> <?php echo $game11; ?> <br> <?php echo $game12; ?> <br> <?php echo $game13; ?> <br> <?php echo $game14; ?> <br> <?php echo $game15; ?> <br> <?php echo $game16; ?> <br /><br /> <input type="Submit" value="Submit Spreads"> </form> I'm wondering if I can use this code for posting to the database (insert_spreads.php): <?php header("Location: admin_schedule.php"); include("opendatabase.php"); $w$weekg$gameA=("$_POST['w$weekg$gameA']"); $w$weekg$gameH=("$_POST['w$weekg$gameH']"); $sql=" UPDATE schedule SET A_pt_spread= '$w$weekg$gameA',H_pt_spread= '$w$weekg$gameH' WHERE week_id = '$week' AND game_id = '$game'; $result = mysql_query($sql) or die(mysql_error().$sql); mysql_close($con) ?> Thanks for helping. I am working on a PHP/MySQL authorization script. The script seems to work initially, but when I try to Login and post the Form ( echo '<form method="post" action=authorize_1.php">'; echo '<table>'; echo '<tr><td>Userid:</td>'; echo '<td><input type="text" name="userid"></td></tr>'; echo '<tr><td>Password:</td>'; echo '<td><input type="password" name="password"></td></tr>'; echo '<tr><td colspan="2" align="center">'; echo '<input type="submit" value="Log in"></td></tr>'; echo '</table></form>'; ) Internet Explorer returns the error that the page is not found.... but I am using one .php file for the authorization so I am sure the page is found because i can see the Login portion. Any ideas as to what is going wrong? I have this code with clears the input box onclick... Code: [Select] <input type="text" name="username" value="Username" onclick="value=''"/> however is there any way to use php to get the value of username, before its posted? that way i can make it so it only clears if the value of username is "username" I've tried this: <?php $xsblock = $_SERVER['HTTP_REFERER']; $url = "testchan"; $pos = strpos($xsblock, $url); if ($pos == false) { die(); } else { echo "content content content content content content content content"; } ?> How can I do this correctly? Thanks in advance! can anyone help me as to whay I get this error: Problem with the query: INSERT INTO options (item_id, option ) VALUES('1', 'hi' ) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option ) VALUES('1', 'hi' )' at line 1 with this code: Code: [Select] foreach($_POST["user"] AS $key => $val) { $user = $val; $id1 = $_POST['id1'][$key]; $sql = "INSERT INTO options (item_id, option ) VALUES('$id1', '$user' )"; $rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error()); } Code: [Select] <input type="checkbox" name="yes" id="checkme" /><div id = "extra"> <div id="user"> Enter User Names:<br> <input type="text" name="user[]"/><br></div> <div id="add_user" style="display: none;"><input type="text" name="user[]"/> |