PHP - Remembering Combobox Selection.
Hi Everyone.
I'm using the following code to populate a combobox with salutations. The List is populated and the initial value is 'select a salutation'. When the submit button is clicked, the selection is saved in the database. my issue is that when i open the page based on the id number, the list does not remember my choice. it just lists all the salutations in the combobox. How can i change this code to remember the value selected? thanks. I am saving the value of Salutation_1 from the combobox into records.Salutation_1. <?php $result=mysql_query("select Salutation from salutations"); $options=""; while ($row=mysql_fetch_array($result)) { $categoryname=$row["Salutation"]; $options.="<OPTION VALUE=\"$categoryname\">".$categoryname.'</option>'; } ?> <select name="Salutation_1"> <option >< select salutation > <?php echo $options ?></option> Similar TutorialsHi Eveyone, Is it possible in php to remember form data when scrolling through pages set up using pagination? Usually i use value="<?php echo $_POST['field_name']; ?>" to remember the form data if the submit button has been pressed. Im trying to get it so that if i fill out a field on page 1, then i go to page 2, if i come back top page 1 the field is still populated. Scrolling through the pages nothing is actually posted so the fields are becoming empty when returning to them. All help is greatly appreciated. Thanks I'm trying to make it to where when a user clicks a link inside of my tabulator table, they can click the back button in their browser and my tabulator table will remember any filters, sorts, and pagination information and restore them to the exact view they had when they left the page. I am going to store the info in a session but I'm having trouble with the logic of it; meaning when and how to update the information in the session. For example: Case 1: User arrive on page for the first time and has no session data so tabulator passes the initial $_GET variables. I process the $_GET vars and then store the information in the session. Case 2: User has session information so I restore their view of the table based on these values. But, now let's say they go to the next page....how would I go about figuring out if I need to update their session values or just restore the values that already exist? Hello Friends, i have work with combobox by inserting value from DB dynamically... i just stuck with the situation as m populating combobox as statically , successfully inserting value in DB... but the point is m not sure for how to select perticular value stored in DB for combobox for displaying the data... here is my attempt... Code: [Select] Name: <input type="text" name="txtName" value="<?php print $uName; ?>"/> <br /> User Type: <select name="selType"> <option value="Admin">Admin</option> <option value="User">User</option> </select> i m getting the value of textbox from select query in the loop bt wht abt combobox value? if for 1 record the name will be krazyk n usertype will be admin then how to select the value from DB? please suggest me the way to accomplish it... awaiting for your better response... Thank you...!!! I have a form gathering data from the database. There is one field 'country' which is a combo box. The combo box is populated from the countries table which joins the customers table to provide the country specific to the customer. I'm trying to have the combo box display the country associated with the customer. I think I'm close in my code, but unsure. This is a playground to so I can implement on our other site. <?php require_once('database.php'); $sql2 = "SELECT * From countries "; $countries = $db->query($sql2); if(isset($_GET['customerID'])) { $customerID = filter_input(INPUT_GET, 'customerID', FILTER_SANITIZE_NUMBER_INT); $sql = "SELECT * FROM customers WHERE customerID =$customerID "; //$sql2 = "SELECT * From countries //INNER JOIN customers ON countries.countryCode=customers.countryCode //WHERE customers.customerID = $customerID"; $stmt = $db->query($sql); } if(isset($_GET['customerID'])){ $customerID = filter_input(INPUT_GET, 'customerID', FILTER_SANITIZE_NUMBER_INT); $countryQuery = " {$sql2} INNER JOIN customers ON countries.countryCode = customers.countryCode WHERE customers.customerID = $customerID"; $countriesQuery = $db->prepare($countryQuery); $countriesQuery->execute(['customerID' => $_GET['customerID']]); $selectedCountry = $countriesQuery->fetch(PDO::FETCH_ASSOC); var_dump($selectedCountry); } ?> <!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"> <!-- the head section --> <head> <title>My Guitar Shop</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <!-- the body section --> <body> <div id="page"> <div id="header"> <h1>SportsPro Technical Support</h1> <p>Sports management software for the sports enthusiast.</p></h1> </div> <div id="main"> <h1>View/Update Customer</h1> <form action="update.php" method="get" > <?php ?> <div id="content"> <!-- display a table of products --> <h2>Customers</h2> <form name="customerInfo"> <?php foreach ($stmt as $cust) { ?> <div> <label>First Name</label> <input type="text" name="name" class ="form-control" value ="<?php echo $cust['firstName']; ?>"> </div><br> <div> <label>Last Name</label> <input type="text" name="name" class ="form-control" value ="<?php echo $cust['lastName']; ?>"> </div><br> <div> <label>Address</label> <input type="text" name="address" class ="form-control" value ="<?php echo $cust['address']; ?>"> </div><br> <div> <label>City</label> <input type="text" name="city" class ="form-control" value ="<?php echo $cust['city']; ?>"> </div><br> <div> <label>State</label> <input type="text" name="state" class ="form-control" value ="<?php echo $cust['state']; ?>"> </div><br> <form action="update.php" method="get"> <select name="country"> <option value=""></option> <?php foreach ($countries->fetchAll() as $country): ?> <option value="<?php echo $country['customerID']; ?> <?php echo isset($customerID) == $selectedCountry['customerID'] ? ' selected':''?> "><?php echo $country['countryName']; ?></option> <?php endforeach;?> </select> </form> </div> <br> <div> <label>Country Code</label> <input type="text" name="countryCode" class ="form-control" value ="<?php echo $cust['countryCode']; ?>"> </div><br> <div> <label>Zip Code</label> <input type="text" name="postalCode" class ="form-control" value ="<?php echo $cust['postalCode']; ?>"> </div><br> <div> <label>Email </label> <input type="text" name="email" class ="form-control" value ="<?php echo $cust['email']; ?>"> </div><br> <div> <label>Phone Number </label> <input type="text" name="phone" class ="form-control" value ="<?php echo $cust['phone']; ?>"> </div><br> <div> <label>Password </label> <input type="text" name="password" class ="form-control" value ="<?php echo $cust['password']; ?>"> </div><br> <div> <?php } ?> </div> </div> <form action="UpdateCustomer.php" method="get"> <input type="submit" name="data" value="Update_Data"></input> </form> <div id="footer"> <p> © <?php echo date("Y"); ?> SportsPro, Inc. </p> </div> </div><!-- end page --> </body> </html>
I trying to display data from a database for editing I have 2 table: 1. tbl_proizvodi_karakteristike (Translate: tbl_product_caracteristics) - In this table i have list of product caracteristic relatet to product 'id' in table 'tbl_product_list' (this 'tbl_product_list' is not important now) - field: id, opis, vrednsot, proizvod_id 2. tbl_karakteristike (Translate: tbl_caracteristic) - In this table i have list of all caracteristic - field: id, opis in field 'opis' in table 'tbl_proizvodi_karakteristike' i insert 'id' from 'tbl_karkateristike' and that works ok with combo box. But, when i try to edit value in 'tbl_proizvodi_karakteristike', i do not know how to show current value in combo box (i have list of value from 'tbl_karakteristike' in combox, starting from first) For examle, if i know that value in selected caracteristics is 'opis = 25', it means that i in combo box on load edit form mast have first value 25 and rest of posible value. For now i have value '1 and rest of value' Hiar is current code in edit form Code: [Select] <form action='product_carasteristic.php?product_id=<?php echo $p_id; ?>&product_name=<?php echo $p_name; ?>' method='POST'> <?php $p_id = $_GET['id']; $karakteristike = mysql_query("SELECT * FROM `tbl_proizvodi_karakteristike` WHERE `id`='$p_id'") or die(mysql_error()); while($row = mysql_fetch_array($karakteristike)){ $p_id = $row['id']; $p_opis = $row['opis']; $p_vrednost = $row['vrednost']; $p_proizvod_id = $row['proizvod_id']; ?> <table> <tr> <td > Karakteristika </td> <td> <select name="opis" style="font-family: verdana; font-size:15px; width:342px;"> <?php $tbl_karakteristike = mysql_query("SELECT * FROM `tbl_karakteristike`") or die(mysql_error()); while($row = mysql_fetch_array($tbl_karakteristike)){ $k_id = $row['id']; $k_opis = $row['opis']; ?> <option value='<?php echo $k_id; ?>'><?php echo $k_opis; ?></option> <?php } ?> </select> </td> </tr> <tr> <td> Vrednost karakteristike </td> <td> <input type="text" name="vrednost" value='<?php echo $p_vrednost; ?>'> </td> </tr> <tr> <td> <input type="submit" name="submit" value="Kreiraj"> </td> <td> Neophodno je popuniti sva polja </td> </tr> </table> <?php } ?> </form> thanks forward I use firebug to detect how javascript work. It same code. the java script :
<script type="text/javascript"> $(function() { $("#cmbNegara").change(function(){ $("img#imgLoad").show(); var kodejeniskayu = $(this).val(); $.ajax({ type: "POST", dataType: "html", url: "getProvinsi.php", data: "kodejeniskayu="+kodejeniskayu, success: function(msg){ if(msg == ''){ $("select#cmbProvinsi").html('<option value="">--Pilih Ukuran--</option>'); $("select#cmbKota").html('<option value="">--Pilih Ukuran--</option>'); }else{ $("select#cmbProvinsi").html(msg); } $("img#imgLoad").hide(); getAjaxAlamat(); } }); }); $("#cmbProvinsi").change(getAjaxAlamat); function getAjaxAlamat(){ $("img#imgLoadMerk").show(); var kodeukuran = $("#cmbProvinsi").val(); $.ajax({ type: "POST", dataType: "html", url: "getKota.php", data: "kodeukuran="+kodeukuran, success: function(msg){ if(msg == ''){ $("select#cmbKota").html('<option value="">--Stok Kosong--</option>'); }else{ $("select#cmbKota").html(msg); } $("img#imgLoadMerk").hide(); } }); }; }); </script>getprovinsi.php <?php require_once('Connections/karyo.php'); ?> <?php ini_set('display_errors',0); //ambil parameter $kodejeniskayu = $_POST['kodejeniskayu']; if($kodejeniskayu == ''){ exit; }else{ $sql ="SELECT kodeukuran,ukuran FROM tukuran WHERE kodejeniskayu='$kodejeniskayu'"; $getNamaProvinsi = mysql_query($sql,$karyo) or die ('Query Gagal'); while($data = mysql_fetch_array($getNamaProvinsi)){ echo '<option value="'.$data['kodeukuran'].'">'.$data['ukuran'].'</option>'; } exit; } ?>getkota.php <?php require_once('Connections/karyo.php'); ?> <?php ini_set('display_errors',0); //ambil parameter $kodeukuran = $_POST['kodeukuran']; if($kodeukuran == ''){ exit; }else{ $sql ="SELECT idstok,harga FROM tstok WHERE kodeukuran = '$kodeukuran'"; $getNamaKota = mysql_query($sql,$karyo) or die ('Query Gagal'); while($data = mysql_fetch_array($getNamaKota)){ echo '<option value="'.$data['idstok'].'">'.$data['harga'].'</option>'; } exit; } ?>the problem at online is, the combobox at getprovinsi not showing up. Is there a simple way to keep a yes or no selection in a drop down menu after the page is submitted? Code: [Select] <form name="survey" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Satisfied<select name="satisfied"> <option value="yes"> yes </option> <option value="no"> no </option> </select> <input name="submit" type="submit" value="Submit"> </form> how do i make it so that all the items appear on eventname Code: [Select] <?php require "scripts/connect.php"; $query = mysql_query("SELECT eventname FROM events"); while ($row = mysql_fetch_array($query)){ $eventname = $row['eventname']; $form = "<form action='addcat.php' method='post'> <table> <tr> <td>SELECT EVENT</td> <td> <select value='$eventname'> <option value='$eventname'>$eventname</option> </select> </td> </tr> <tr> <td>SELECT VENUE</td> <td> <select> <option></option> </select> </td> </tr> <tr> <td>SELECT CATEGORY</td> <td> <select> <option>FOOTBALL</option> <option>BASKETBALL</option> <option>HOCKEY</option> <option>DRAMA</option> <option>MUSIC</option> <option>DANCE</option> <option>VISUAL ARTS</option> </select> </td> </tr> </table> </form>"; echo "$form"; } ?> My website, http://www.LawnBagSigns.com, has a lot of price tables, which I think, are getting bulky and hard to read. Like this price page here, I think the table might be scaring people away. So here is what I want to try - have a series of dropdown boxes where the user can choose the details a product one by one (for example, first the size, then the quantity). I want to do this in PHP and XML, and I want to avoid JavaScript since, believe it or not, not all of my website's visitors have JavaScript enabled. My problem at the moment is that the XML document is full of white scape that is screwing over my system, but I don't want to sacrifice readability by blobbing the whole xml file into one line with no spaces (because if I want to change or add something... you get the idea). So my question is, how do I get rid of the white scape? Here is the prototype I've been working on: http://www.lawnbagsigns.com/flyers-test.php The XML: Code: [Select] <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="whitespace_ripper.xsl"?> <price_table> <side>1 <qty>25 <size>3.5 x 8.5 <price> 37 </price> </size> <size>8.5 x 5.5 <price> 37 </price> </size> <size>4.25 x 11 <price> 37 </price> </size> <size>8.5 x 7 <price> 38 </price> </size> </qty> </side> <side>2 <qty>25 <size>3.5 x 8.5 <price> 37 </price> </size> <size>8.5 x 5.5 <price> 37 </price> </size> <size>4.25 x 11 <price> 37 </price> </size> <size>8.5 x 7 <price> 38 </price> </size> </qty> </side> </price_table>and the PHP code: Code: [Select] <?php //P Session function priceSelect ($path) { if (!empty($_REQUEST['Previous'])) { $_SESSION['xmlCursor'] = $_SESSION['xmlCursor']->parentNode; echo 'test1<br />'; } elseif (!empty($_REQUEST['Next'])) { $exitLoop = false; $childCursor = $_SESSION['xmlCursor']->firstChild; while ($exitLoop == false) { if ($childCursor == $_SESSION['choice']) { $_SESSION['xmlCursor'] = $childCursor; $exitLoop = true; } else { $childCursor = $childCursor->nextSibling; } } echo 'test2<br />'; } else { $_SESSION['userMadeChoices'] = array(array()); $_SESSION['xmlCursor'] = loadXML($path); echo $_SESSION['xmlCursor']->firstChild->nodeValue; echo $_SESSION['xmlCursor']->parentNode->nodeValue; echo 'test3<br />'; } $reload = $_SERVER['PHP_SELF']; echo '<form action="'.$reload.'" method="post">'; displayChoices($_SESSION['userMadeChoices']); echo 'test4<br />'; displayMenu($_SESSION['xmlCursor'], $_SESSION['userMadeChoices'] ); echo 'test5<br />'; displayButtons($_SESSION['xmlCursor']); echo 'test6<br />'; echo '</form>'; } function loadXML($path) { $xmlDoc = new DOMDocument(); $xmlDoc->load($path); $xmlDoc = $xmlDoc->documentElement; return $xmlDoc; } function displayChoices($data) { for ($i = 0; $i < count($data); $i ++) { echo $data[$i][0]; echo '</br>'; } } function displayMenu($xml, $data) { echo '<select name="choice">'; //$xml = $xml->documentElement; //$data[$xml] = foreach($xml->childNodes AS $child) { echo '<option value="' . $child->firstChild->nodeValue . '">' . $child->firstChild->nodeValue . '</option>'; } echo '</select>'; } function displayButtons($xml) { if ($xml->childNodes != null) { echo '<input type="submit" name="Previous" value="Previous Step" />'; } if ($xml->parentNode != null) { echo '<input type="submit" name="Next" value="Next Step" />'; } } function stripWhitespace ($string) { return $string; } ?> Hi all, I will wish to modify this code to get a choice of multiple selection, so I can select multiple category and not a single as it is currently. Here is the original code: Code: [Select] {if $step==1} <div class="form_content"> <form name="newad" method="post" action="newad.php?step=1"> <label>{$lng.listings.category}<span class="mandatory"> *</span></label> <select id="category" name="category"> <option value="">{$lng.listings.category}</option> {foreach from=$categories item=v name=cat} {if $v.parent==1} <optgroup label="{$v.str}{$v.name}"> {else} <option value="{$v.id}" {if $tmp.category==$v.id}selected="selected"{/if}>{$v.str}{$v.name|escape:"html"}</option> {if ( $smarty.foreach.cat.index!=$categories|@count-1 && $v.parent_id!=$categories[$smarty.foreach.cat.iteration].parent_id) || ($smarty.foreach.cat.index==($categories|@count-1) && $v.parent_id!=0)} </optgroup> {/if} {/if} {/foreach} </select> {* ----------------------- levels drop down categories --------------------- *} {* <div> <select id="category1" name="category1" class="levels" onChange="chooseCateg(this.form, 1)"> <option value="">{$lng.listings.category}</option> {foreach from=$categories item=v name=cat} {if $v.parent_id==0} <option value="{$v.id}">{$v.name|escape:"html"}</option> {/if} {/foreach} </select> </div> <div style="display: none;" id="level2"> <select id="category2" name="category2" class="levels" onChange="chooseCateg(this.form, 2)"> </select> </div> <div style="display: none;" id="level3"> <select id="category3" name="category3" class="levels" onChange="chooseCateg(this.form, 3)"> </select> </div> <div style="display: none;" id="level4"> <select id="category4" name="category4" class="levels" onChange="chooseCateg(this.form, 4)"> </select> </div> <div style="display: none;" id="level5"> <select id="category5" name="category5" class="levels" onChange="chooseCateg(this.form, 5)"> </select> <input type="hidden" name="category" id="category" /> </div> *} <br/><br/> <div class="buttons"><strong><input type="submit" name="Choose_categ" id="Choose_categ" value="{$lng.listings.next_step}" /></strong></div> <div class="clearfix"></div> </form> </div> </div> {* end form_container *} {/if} {* end step1 *} Thank you for your help Hi! I want to have a first page on my website where you as visitor can choose the preferred language. No login at all. I want to save this choice in a cookie or something. The easiest way So next time he/she visits, the language choice is already made for he/she. Any good suggestions for a php code that works? When I try to select more than one value for my report, only one value shows. I tried a few things, but I'm not having any luck. Here is the form code: Code: [Select] <td style="text-align: right">Job Type:</td> <td> <select name="job_type" multiple="multiple" size="3"> <option value="0" selected>ALL</option> {section name=jt loop=$job_type_list} <option value="{$job_type_list[jt][0]}">{$job_type_list[jt][1]}</option> {/section} </select> </td> Here is the other code: //All IIS Object Code is to be encapsulated in the execute_object function function execute_object($tab){ if ((isset($_POST['job']) and isset($_POST['job_type']) and isset($_POST['child_type']) and isset($_POST['job_status']) and isset($_POST['child_status']) and isset($_POST['ou']) and isset($_POST['child_ou']) and isset($_POST['pm']) and isset($_POST['child_pm']) and isset($_POST['dm']) and isset($_POST['child_dm']) and isset($_POST['customer']) and isset($_POST['end_date'])) or (isset($_SESSION['report_job']) and isset($_SESSION['report_job_type']) and isset($_SESSION['report_child_type']) and isset($_SESSION['report_job_status']) and isset($_SESSION['report_child_status']) and isset($_SESSION['report_ou']) and isset($_SESSION['report_child_ou']) and isset($_SESSION['report_pm']) and isset($_SESSION['report_child_pm']) and isset($_SESSION['report_dm']) and isset($_SESSION['report_child_dm']) and isset($_SESSION['report_customer']) and isset($_SESSION['report_end_date']))) { //Include functions include $GLOBALS['include_path']."penta.job.functions.php"; include $GLOBALS['include_path']."display.functions.php"; include $GLOBALS['include_path']."report.functions.php"; //Get report parameters if (isset($_POST['job'])){ $job_id = $_POST['job']; } else { $job_id = $_SESSION['report_job']; } if (isset($_POST['job_type'])){ $job_type = $_POST['job_type']; } else { $job_type= $_SESSION['report_job_type']; } if (isset($_POST['child_type'])){ $child_type = $_POST['child_type']; } else { $child_type= $_SESSION['report_child_type']; } if (isset($_POST['exclude_type'])){ $exclude_type = 1; } else { if(isset($_SESSION['report_exclude_type'])){ $exclude_type = $_SESSION['report_exclude_type']; } else { $exclude_type = 0; } } if (isset($_POST['job_status'])){ $job_status = $_POST['job_status']; } else { $job_status= $_SESSION['report_job_status']; } if (isset($_POST['child_status'])){ $child_status = $_POST['child_status']; } else { $child_status= $_SESSION['report_child_status']; } if (isset($_POST['ou'])){ $ou_id = $_POST['ou']; } else { $ou_id = $_SESSION['report_ou']; } if (isset($_POST['child_ou'])){ $child_ou_id = $_POST['child_ou']; } else { $child_ou_id = $_SESSION['report_child_ou']; } if (isset($_POST['pm'])){ $pm_id = $_POST['pm']; } else { $pm_id = $_SESSION['report_pm']; } if (isset($_POST['child_pm'])){ $child_pm_id = $_POST['child_pm']; } else { $child_pm_id = $_SESSION['report_child_pm']; } if (isset($_POST['dm'])){ $dm_id = $_POST['dm']; } else { $dm_id = $_SESSION['report_dm']; } if (isset($_POST['child_dm'])){ $child_dm_id = $_POST['child_dm']; } else { $child_dm_id = $_SESSION['report_child_dm']; } if (isset($_POST['customer'])){ $cus_id = $_POST['customer']; } else { $cus_id = $_SESSION['report_customer']; } if (isset($_POST['sort_by_cust'])){ $sort_by_cust = 1; } else { if(isset($_SESSION['report_sort_by_cust'])){ $sort_by_cust = $_SESSION['report_sort_by_cust']; } else { $sort_by_cust = 0; } } if (isset($_POST['end_date'])){ $edate = $_POST['end_date']; } else { $edate = $_SESSION['report_end_date']; } $job_type = implode(",",$_POST['job_type']); //Prepare to output report $filename = "Project Review Report.xls"; if (isset($_POST['print'])){ //Prepare the output file header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=\"$filename\""); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); header("Pragma: public"); } else { //Save the report parameters to enable printing from the preview $_SESSION['report_job'] = $job_id; $_SESSION['report_job_type'] = $job_type; $_SESSION['report_child_type'] = $child_type; $_SESSION['report_exclude_type'] = $exclude_type; $_SESSION['report_job_status'] = $job_status; $_SESSION['report_child_status'] = $child_status; $_SESSION['report_ou'] = $ou_id; $_SESSION['report_child_ou'] = $child_ou_id; $_SESSION['report_pm'] = $pm_id; $_SESSION['report_child_pm'] = $child_pm_id; $_SESSION['report_dm'] = $dm_id; $_SESSION['report_child_dm'] = $child_dm_id; $_SESSION['report_customer'] = $cus_id; $_SESSION['report_sort_by_cust'] = $sort_by_cust; $_SESSION['report_end_date'] = $edate; //Output a print button at the start of the preview preview_print_button("load_object.php?&object=52.2"); } //Get the list of jobs based on the given criteria $job_list = report_job_list($job_id, $job_type, $child_type, $exclude_type, $job_status, $child_status, $ou_id, $child_ou_id, $pm_id, $child_pm_id, $dm_id, $child_dm_id, $cus_id, $sort_by_cust, $selected_by); //Set the max script execution time to ensure it can finish based on the number of jobs $num_jobs = $job_list->RecordCount(); set_time_limit(60 + ($num_jobs * 30)); //Parse the template $template = $GLOBALS['reports_path']."report52.2.htm"; $default_logo = "report52.2_files/image001.gif"; $hdr = null; $ftr = null; parse_template($template, $default_logo, $hdr, $ftr); How can I prevent someone from making an ivalid selection in a form? Lets say I had a select dropdown box and someone saved the HTML source from the browser, changed an item in the list, and changed the action to point back to my server eg. action="testsite.com/index.php". Then they open the file and try to submit the form.
Hi, I'm basically trying to write something like the below: $uri = "1"; $uri = "2"; if ($uri == "1") { echo 'test 1'; } if ($uri == "2") { echo 'test 2'; } if ($uri == "3") { echo 'test 3'; } I will define $uri on every page and I want the php to process what to display on the page, ie test 1, test 2 and/or test 3 Hi I have to multi select tables, the table on the left is field with the contents of an array, I then have it so the user can make there selections from the left box and move them into the right. They then hit submit and it gets stored inmysql table as an array. The problem I am having is keeping the selections in that right box after any sort of page refresh. Any ideas I have pasted the php and html code below, the add/remove function is controlled by javascript, I won't bother pasting that as i don't think it has anything to do with it. PHP ******** Code: [Select] <?php / ------- PARSING PERSONAL TRAINER DETAILS VENUE --------- if ($_POST['parse_var'] == "fromPool"){ $venue = $_POST['venue']; if (is_array($_POST['venue'])) { $venue = explode("\n", $_POST['venue']); } else { $venue = $_POST['venue']; } // Update the database data now here for all fields posted in the form $sqlUpdate = mysql_query("UPDATE ptdata SET venue='$venue' WHERE id='$id' LIMIT 1"); if ($sqlUpdate){ $success_msg = '<img src="images/Form/round_success.png" width="20" height="20" alt="Success" />Your venue information has been updated successfully'; } else { $error_msg = '<img src="images/Form/round_error.png" width="20" height="20" alt="Failure" /> ERROR: Problems arose during the information exchange, please try again later</font>'; } } // ------- END PARSING PERSONAL TRAINER DETAILS VENUE --------- ?> <?php ////////// Venue Array PHP For Multi Selection Boxes //////////// $dbString = ''; // To be pulled from Database $toPool = explode(',', $dbString); $pool = Array('Your Home','My Home','Outside','Private Studio','Your Work','Gym'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $toPool = (count($_POST['venue']) > 0)? $_POST['venue'] : Array(); $newDbString = implode(',', $toPool); // Store in Database; } $fromPool = array_diff($pool, $toPool); ?> html *********** <form action="ptmemberaccount.php" method="post" enctype="multipart/form-data"onsubmit="multipleSelectOnSubmit()"> <table width="500" align="left"> <tr> <td width="500" height="300" align="center"> <select multiple="multiple" name="fromBox[]" id="fromBox"> <?php foreach($fromPool as $itm){ echo "\t" . '<option value="' . $itm . '">' . $itm . '</option>' . PHP_EOL; } ?> </select> <select multiple="multiple" name="venue[]" id="toBox"> <?php foreach($toPool as $itm){ echo "\t" . '<option value="' . $itm . '">' . $itm . '</option>' . PHP_EOL; } ?> </select> </td> </tr> <tr> <td align="center" height="35"><script type="text/javascript"> createMovableOptions("fromBox","toBox",400,200,'Training Venues','Selected Training Venues'); </script> <p>Use the buttons to Add/Remove selections</p></td></td> </tr> <tr> <td align="center" height="100"> <input type="submit" value="OK"> </tr> </table> </form> If you need anymore info let me know, also if anyone knows a better way of achieving this i am open to suggestions. Many Thanks MOD EDIT: code tags added When you select language I just got an error message Got an error message that says: This problem can sometimes occur if you are disabled or refused to take accept cookies. I have accepted cookies. My code is: language.php <?php if(!isset($_COOKIE['language'])) { if(!isset($_GET['lang'])) { ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>123</title> <style type="text/css"> <!-- body { background-image: url(images/background.jpg); } .style1 { color: #FFFFFF; font-weight: bold; } --> </style></head> <body> <p><br> <br> <br> <br> <br> </p> <div align="center" style="margin-top:400px;"> <table width="200" border="0"> <tr> <td width="114"><div align="left"><a href="language.php?lang=swe"><img src="http://www.clickbuxer.com/images/swe.jpg" border="0" alt="swedish" /></a></div></td> <td width="1" rowspan="2"> </td> <td rowspan="2"><div align="left"></div></td> <td><a href="language.php?lang=usa"><img src="http://www.clickbuxer.com/images/usa.jpg" border="0" alt="usa" /></a></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><div align="center" class="style1">SWE</div></td> <td> </td> <td width="0"><div align="center"></div></td> <td width="110"><div align="center" class="style1">USA</div></td> </tr> </table> </div> <p align="center"> </p> </body> </html> <?php } else { //Add cookie code $language = $_GET['lang']; setcookie("language", $language, time()+3600);//set to expire in 1 hour, 3600=seconds switch($language) { case usa: $redirect = "http://www.clickbuxer.com"; break; case swe: $redirect = "http://www.clickbuxer.com/sv/index.php"; break; default: $redirect = "http://www.clickbuxer.com"; } header("Location: $redirect"); } } else { //If cookie is already set $language = $_COOKIE['language']; switch($language) { case usa: $redirect = "http://www.clickbuxer.com"; break; case swe: $redirect = "http://www.clickbuxer.com/sv/index.php"; break; default: $redirect = "http://www.clickbuxer.com"; } header("Location: $redirect"); } ?> index.php <?php if(!isset($_COOKIE['language'])) { header("Location: http://www.clickbuxer.com/language.php"); } else { $language = $_COOKIE['language']; switch($language) { case usa: $redirect = "http://www.clickbuxer.com"; break; case swe: $redirect = "http://www.clickbuxer.com/sv/index.php"; break; default: $redirect = "http://www.clickbuxer.com"; } header("Location: $redirect"); } ?> if a user were to select multiple items in a selection list I would like to concatenate those items into a list and assign that into a variable. I know I should loop through the list but i'm not sure how I would continue to add those values to a variable. Hello all, I have a contact form which has a drop-down-menu (the reason why a user is using the form). I am wanting the option which has been selected to appear in the PHP scripted email as the subject. I am just sat here staring at the code and getting nowhere with it. Could anyone help me? HTML form Code: [Select] <form name="contact_form" method="post" action="mail.php" onsubmit="return validate_form();"> <p>Full Name <em>(required)</em>:<br /> <input class="tb-focus" type="text" name="name" id="name" size="40" value="" /></p> <p>Reason for Contact:<br /> <select class="select"> <option value="CV">CV Request</option> <option value="enquiry">General Enquiry</option> <option value="request">Request for Audition</option> </select> <p>Email Address <em>(required)</em>:<br /> <input class="tb-focus" type="text" name="email" id="email" size="40" value="" /></p> <p>Agency Name <em>(if applicable)</em>:<br /> <input class="tb-focus" type="text" name="business" id="business" size="40" value="" /></p> <p>Contact Number <em>(required)</em>:<br /> <input class="tb-focus" type="text" name="number" id="number" size="40" value="" /></p> <p>Message <em>(required)</em>:<br /> <textarea class="tb-focus" name="message" id="message" rows="6" cols="40"></textarea></p> <p><input class="button" type="submit" value="Submit Form" /></p> </form> PHP email POST: Code: [Select] <?php // Assign the posted values as variables to use later $name = $_POST['name']; $email = $_POST['email']; $reason = $_POST['sdsdsd']; $business = $_POST['business']; $number = $_POST['number']; $message = $_POST['message']; $to = "*********"; $subject = "Email Contact Form - " . $_POST[name]; $message = "Filled out contact form on portfolio website.\n \n Full Name: " . $_POST[name] . "\n Email: " . $_POST[email] . "\n Business Name: " . $_POST[business] . "\n Contact Number: " . $_POST[number] . "\n Message: " . $_POST[message]; //leave the next 2 lines alone $headers .= "MIME-Version: 1.0rn"; $headers .= "Content-Type: text/html; charset=ISO-8859-1rn"; if (empty($name) || empty($email) || empty($number) || empty($message)) { echo "<p>You appear to not have filled in the necessary fields.</p>"; echo "<p>Please click <a href='contact.html'>here</a> to re-enter your information.</p>"; } elseif(!mail($to, $subject, $message, $headers)){ echo "Sorry, there has been an error! Please try sending your message again. Click <a href='contact.htm'>here</a> to start again."; } else { echo "Thank you for taking the time to fill out the contact form. I will get back to you as soon as I can."; } ?> I have absolutely no idea where to start with this. Thanks in advance for the help |