PHP - Multiple Selection
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 Similar TutorialsWhen 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); 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. Quote
I have this code here. i wanted to know how i can be able to make multiple selections from the returned data from the database and how to save them Quote
<select name="troom" multiple class="form-control" required> <option selected="true" disabled="disabled">--Select a room--</option> $records =mysqli_query($con, "select * from room where TRoom not in (select TRoom from roombook where cin <= '$checkout' and cout >= '$checkin');"); while ($data = mysqli_fetch_array($records)) { echo "<option value='" . $data['TRoom'] . "'>" . $data['TRoom'] . "</option>"; //displaying data in option menu } } ?> </select>
Hi, I m trying to add items from a master list to each sub process. But, I failed to proceed on what i intend to do. 1) i need to select an process from the combo box. 2) from the master list, i hv to check the item which belong to the process. 3) upon submitting, save into database. 4) the it will show those are already checked or unchecked. here is the codes i hv done: Code: [Select] <?php require_once '../../connectDB.php'; require_once '../include/paginator.class.php'; $sql="SELECT * FROM tb_item"; $result = mysql_query($sql) or die(mysql_error()); $pages = new Paginator; $pages->items_total = mysql_num_rows($result); $pages->mid_range = 5; $pages->items_per_page = 100; $pages->paginate(); $sql="SELECT * FROM tb_item ORDER BY itm_tcpd ASC $pages->limit"; $result = mysql_query($sql) or die(mysql_error()); function createComboBox() { $sql = "SELECT tb_process.pro_name, tb_process.pro_id, tb_sub_process.sub_id, tb_sub_process.sub_name FROM tb_process INNER JOIN tb_sub_process ON tb_process.pro_id = tb_sub_process.pro_id ORDER BY pro_name"; $result = mysql_query($sql) or die('Cannot get Process. ' . mysql_error()); $group = array(); while ($row = mysql_fetch_assoc($result)) { $group[$row['pro_name']][] = $row; } echo "<table> <tr> <td>Add item into :</td> <td> <select name='cboSub' id='cboSub'> <option value='0' selected='selected'>----- Selection -----</option>"; foreach ($group as $key => $values) { echo " <optgroup label='$key'>"; foreach ($values as $value) { $select = ($id == $value['sub_id']) ? 'selected="selected"' : NULL; echo '<option value="'.$value['sub_id'].'"'.$select.'>'.$value['sub_name'].'</option>'; } echo " </optgroup>"; } echo " </select> </td> </tr> </table>"; } if(isset($_POST['add'])) { $id = $_POST['checkbox']; foreach($id as $key=>$val) { $sql = "INSERT INTO tb_record (rec_tpcd, sub_id) VALUES ('$key', '$sub_id')"; $result = mysql_query($sql); } echo(" <SCRIPT LANGUAGE='JavaScript'> window.alert('Items has been added into the database.'); window.location='addItem.php'; </SCRIPT>"); } ?> <!DOCTYPE div PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript"> $().ready(function() { $("#cboSub").change("get_tpcd.php", { }); }); </script> </head> <body> <div> <table width="100%"> <tr> <td width="65%"><?php createComboBox(); ?></td> <td width="30%"><?php echo $pages->display_pages(); ?></td> <td width="5%"><?php echo $pages->display_jump_menu(); ?></td> </tr> </table> </div> <div> <form method='post' action=''> <table width='100%' border='1' align='left' cellpadding='5' cellspacing='1'> <tr> <?php $numCol = 5; $count = 0; for($i=0; $i<$numCol; $i++) { echo "<th align='center'>TPCD No.</th> <th align='center'>Check / Uncheck</th>"; } while ($row = mysql_fetch_array($result)) { extract($row); if($count % $numCol == 0) { echo '</tr><tr>'; } echo " <td align='center'>".$itm_tcpd."</td> <td align='right'><input type='checkbox' name='checkbox[".$itm_tcpd."]' id='checkbox' ".$checked."></td>"; $count++; } ?> </tr> <tr> <td colspan='10' align='right'> <input type='submit' name='add' id='add' value='Add TPCD'> </td> </tr> </table> </form> </div> </body> </html> the output is something similar as in the attachment. any helps are vy welcome and appreciated. regards, juz [attachment deleted by admin] Hi I have a results page from a MySQL query and I have implemented pagination to present data in chunks of 25 per page in a table view (each row => 1 entry). My problem is that next to each data row, I have a selection checkbox, and if the user clicks on it, he can download the selected entries. This thing worked OK before I employed paginated view, when I presented all data in one page. Now, if I select e.g. 2 entries in page 1, then I jump to page 12 and select another 2 entries, if I click on the "Retrieve" button, I get only the last 2 entries (from the last page visited). How can I solve this problem? With JS? Can I use PHP only? Hello, I am trying to update my database with multiple array values like this. if (isset($_POST['submit_multiple'])) { $id=$_POST['selector']; $class=$_POST['class']; $section=$_POST['section']; $N = count($id); for($i=0;$i<$N;$i++) { echo "update table1 set transfer_status='yes',transfer_date='".date('Y-m-d')."',class='".$class[$i]."',section='".$section[$i]."' where enroll_no='".$id[$i]."'"; }and in the form <form action="transfer_mul_student.php" method="post"><select name="class[]"> <option value="">--SELECT CLASS--</option> <option value="Nursery">Nursery</option> <option value="LKG">LKG</option> <option value="UKG">UKG</option> <option value="I">I</option> <option value="II">II</option> <option value="III">III</option> <option value="IV">IV</option> </select> <select name="section[]"><option value="">--SELECT SECTION--</option> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select><input name="selector[]" id="selector" type="checkbox" value="<?php echo $row['enroll_no']; ?>" /> <input type="submit" class="delete_multiple" value="Transer" name="submit_multiple" />Here $row['enroll_no']is from table student. I have attached the screenshot for the page display with form err1.PNG 12.04KB 0 downloads, In that If i select checkbox1, checkbox2 checkbox3.. it takes the value for class and section properly, but if i select checkbox1, checkbox3, it takes value for 1st record properly and for 2nd one it takes blank value for class and section. How to overcome this? Please suggest Hello, I had 8 select boxes(dropdowns) in a form. Its like a search kind of implementation in the website. I don't know what the user selects, he may choose different select boxes, any number of select boxes. So, based upon the user selection, I need to generate the data. The data fields to be generated would be almost same. So, How would I know what the user selection is and how many select boxes has been selected and how could I generate different data based upon selected boxes. I had to make a small note abt this, that the data generation fields may change for some of the user select combinations, but most of the result fields would be same. so, can you please help me out, how to do, how to make different combination data generations, because, i had 8 fields, i had to make 8! combinations, that would result in a big code. 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"; } ?> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351561.0 First, Happy X-Mas to all! I want to do a form for entering dog-show results. On first site of form the user is able to enter how many dogs for each class (there are youth and open class for example) he want to insert. So on second site there will be formfields for every dog in every class, created with php. User should be able to take dogname from jquery autocomplete - this works for multiple fields. But i need the according id to the dogname - and actual only one id is given - the first one is changing by choosing from autocomplete in next fields... Data came from a json array like 0: {dogidindatabase: "9892", value: "Excalibur Khali des Gardiens de la Cour ",…} dogidindatabase: "9892" label: "<img src='../main/img/female.png' height='20'>Excalibur Khali des Gardiens de la Cour " value: "Excalibur Khali des Gardiens de la Cour " 1: {dogidindatabase: "15942", value: "Excalibur from Bandit's World Kalli",…} dogidindatabase: "15942" label: "<img src='../main/img/male.png' height='20'>Excalibur from Bandit's World Kalli" value: "Excalibur from Bandit's World Kalli"all i need is inside ... the script in form is <script type='text/javascript'> //<![CDATA[ $(function() { $(".dog").autocomplete({ source: "xxx.php", minLength: 3, select: function(event, ui) { $('#dogidindatabase').val(ui.item.dogidindatabase); } }); $["ui"]["autocomplete"].prototype["_renderItem"] = function( ul, item) { return $( "<li></li>" ) .data( "item.autocomplete", item ) .append( $( "<a></a>" ).html( item.label ) ) .appendTo( ul ); }; }); //]]> </script>and the form looked like <input type='text' name='dog' class='dog' value='".strip_tags(${'dogname' .($countbabymale+1)})."' size='35' data-required='true' /><br> <input class='readonly' readonly='readonly' type='text' id='dogidindatabase' name='dogidindatabase' size='5' />I changed in script and form id='dogidindatabase' to class, but it doesn´t work. Testsite is under http://www.wolfdog-d...how.php?lang=de (only german at first) - Insert a number (higher than 1) under baby 3-6 (first box, the others are not working for testing); submit to get to page 2; you see all post-variables (for testing). Try to insert a dogname in first input-field (choose "exc") and insert first one - the id is under dogname. In second dogname inputfield you can choose second dog - the id for the first one changes to id of seond one .... How can i get both for every dog? Ok I'm trying to insert multiple rows by using a while loop but having problems. At the same time, need to open a new mysql connection while running the insert query, close it then open the previous mysql connection. I managed to insert multiple queries before using a loop, but for this time, the loop does not work? I think it is because I am opening another connection... yh that would make sense actually? Here is the code: $users = safe_query("SELECT * FROM ".PREFIX."user"); while($dp=mysql_fetch_array($users)) { $username = $dp['username']; $nickname = $dp['nickname']; $pwd1 = $dp['password']; $mail = $dp['email']; $ip_add = $dp['ip']; $wsID = $dp['userID']; $registerdate = $dp['registerdate']; $birthday = $dp['birthday']; $avatar = $dp['avatar']; $icq = $dp['icq']; $hp = $dp['homepage']; echo $username." = 1 username only? :("; // ----- Forum Bridge user insert ----- $result = safe_query("SELECT * FROM `".PREFIX."forum`"); $ds=mysql_fetch_array($result); $forum_prefix = $ds['prefix']; define(PREFIX_FORUM, $forum_prefix); define(FORUMREG_DEBUG, 0); $con = mysql_connect($ds['host'], $ds['user'], $ds['password']) or system_error('ERROR: Can not connect to MySQL-Server'); $condb = mysql_select_db($ds['db'], $con) or system_error('ERROR: Can not connect to database "'.$ds['db'].'"'); include('../_phpbb_func.php'); $phpbbpass = phpbb_hash($pwd1); $phpbbmailhash = phpbb_email_hash($mail); $phpbbsalt = unique_id(); safe_query("INSERT INTO `".PREFIX_FORUM."users` (`username`, `username_clean`, `user_password`, `user_pass_convert`, `user_email`, `user_email_hash`, `group_id`, `user_type`, `user_regdate`, `user_passchg`, `user_lastvisit`, `user_lastmark`, `user_new`, `user_options`, `user_form_salt`, `user_ip`, `wsID`, `user_birthday`, `user_avatar`, `user_icq`, `user_website`) VALUES ('$username', '$username', '$phpbbpass', '0', '$mail', '$phpbbmailhash', '2', '0', '$registerdate', '$registerdate', '$registerdate', '$registerdate', '1', '230271', '$phpbbsalt', '$ip_add', '$wsID', '$birthday', '$avatar', '$icq', '$hp')"); if (FORUMREG_DEBUG == '1') { echo "<p><b>-- DEBUG -- : User added: ".mysql_affected_rows($con)."<br />"; echo "<br />-- DEBUG -- : Query used: ".end($_mysql_querys)."</b></p><br />"; $result = safe_query("SELECT user_id from ".PREFIX_FORUM."users WHERE username = '$username'"); $phpbbid = mysql_fetch_row($result); safe_query("INSERT INTO `".PREFIX_FORUM."user_group` (`group_id`, `user_id`, `group_leader`, `user_pending`) VALUES ('2', '$phpbbid[0]', '0', '0')"); safe_query("INSERT INTO `".PREFIX_FORUM."user_group` (`group_id`, `user_id`, `group_leader`, `user_pending`) VALUES ('7', '$phpbbid[0]', '0', '0')"); mysql_close($con); } include('../_mysql.php'); mysql_connect($host, $user, $pwd) or system_error('ERROR: Can not connect to MySQL-Server'); mysql_select_db($db) or system_error('ERROR: Can not connect to database "'.$db.'"'); } So I need to be able to insert these rows using the while loop.. how can I do this? I really appreciate any help. 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, 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 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 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? This seems to be a bit of a challenge but I am creating a multiple page form and on one of the pages I have a select field. I would like the user to have the ability to select multiple options but I am using some functions to move the data in hidden fields from page to page. I don't think my functions are jiving with my my foreach loop cause I keep getting an invalid argument error. Thanks in advance for any help. Here is my function: function setSelected($fieldName, $fieldValue) { if(isset($_POST[$fieldName]) && $_POST[$fieldName] == $fieldValue) { echo 'selected="selected"'; } } And here is my loop: $selections = ""; if(isset($_POST["selections"])) { foreach ($_POST["selections"] as $selection) { $selections .= $selection . ", "; } } Hello all, I am trying to learn OOP in PHP so please forgive my ignorance. I seem to be having difficulty inserting data into my database from checkbox items. My database has a column for each each fruit. I would like for each column to be populated with either a one(1) for checked or a zero(0) for not checked. Currently, my attempts have failed. I can either get all checkboxes to insert all zeros or I can get the first column to insert a one(1) while the others as zeros. Is there anybody here that can help me figure out what I am doing wrong and help me to re-work my code so I can get this to work? If anybody can help me using OOP methods that would be fantastic. Thank you all in advance.
$preffruit->create_preffruit(array( 'fruit_apple' => escape(Input::get(['fruit_selection'][0]) ? 1 : 0), 'fruit_orange' => escape(Input::get(['fruit_selection'][1]) ? 1 : 0), 'fruit_banana' => escape(Input::get(['fruit_selection'][2]) ? 1 : 0), 'fruit_pear' => escape(Input::get(['fruit_selection'][3]) ? 1 : 0), 'fruit_kiwi' => escape(Input::get(['fruit_selection'][4]) ? 1 : 0) )); <input type="checkbox" name="fruit_selection[]" value="fruit_apple"> <input type="checkbox" name="fruit_selection[]" value="fruit_orange"> <input type="checkbox" name="fruit_selection[]" value="fruit_banana"> <input type="checkbox" name="fruit_selection[]" value="fruit_pear"> <input type="checkbox" name="fruit_selection[]" value="fruit_kiwi"> public function insert_preffruit($table, $fields = array()) { $keys = array_keys($fields); $values = ''; $x = 1; foreach($fields as $field) { $values .= '?'; if($x < count($fields)) { $values .= ', '; } $x++; } $sql = "INSERT INTO preffruit (`user_id`, `" . implode('`, `', $keys) . "`) VALUES (LAST_INSERT_ID(), {$values})"; if(!$this->query($sql, $fields)->error()) { return true; } return false; } Edited September 23, 2020 by ke-jo Ok so i want to grab an id from the checkbox then grab the option drop down associated with that check box and update a mysql row here is my code so far any help is awesome help taaaanks guys <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query = "SELECT * FROM tickets ORDER BY id DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { print "<input name='delete[]' value='{$row['id']}' type='checkbox'>"; mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query2 = "SELECT * FROM admin"; $result2 = mysql_query($query2) or die(mysql_error()); print "<form name='namestoupdate' method='post' action='update.php'>\n"; print '<select>'; while($row2 = mysql_fetch_array($result2)) { if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$i++.']">'.$row2['user'].'</option>';} } print '</select>'; print "<input type='submit' value='submit' />"; print "</form>"; } ?> Visual aid |