PHP - Problem With Select Boxes
Hey guys,
My problem is, iam loading with mysql_fetch_array a table from my database and draw it into my website page.
The table is a user table which has an id, user, password and rights(Admin, Mod , User).
Only the rights are given out as <select> </select> boxes with the 3 options(Admin, Mod , User).
And i also have 1 more column which has for each row a href to a new site with the id of the array_index as paramter.
My Problem is i want to know which select box was changed and which option is selected so i can change the rights in my database of this user with the right id.
At the moment i cant post the code in here cause i have a problem with my laptop now.
I hope you can help me,
Thank you
Edited by Kandey, 30 October 2014 - 02:28 PM. Similar TutorialsHi There, Is there any way that I can get a select box to auto-select the value from a SQL query? For example, if I have a select box like this: Dave,Jon,Simon,Fred And a select statement that brings back the value of Fred then the select box (in HTML) would: <select name='people'><option>Dave</option><option>Jon</option><option>Simon</option><option selected='selected'>Fred</option></select> Same as if the name was Dave, or Simon etc etc. Hope that makes sense? Cheers Matt Brand new to the forum, and have only been working with HTML, PHP, & MySQL for about 3 months. I've run into an issue I can't seem to figure out how to work around. I want to have two select boxes, that are dependent on one another. For Example: First box lists types of games: RPG LARP Board Game Miniatures CCG The second box displays game names of the type selected above. I have a MySQL table setup for the second box. To be honest I kinda already have it working... with one small but MAJOR glitch. I select the first box and the page submits using onchange='this.form.submit()'. When the page reloads the first select box reverts back to it's default setting, but the second box does correctly filter & show the content based on the selection that was made in the first box. My Question: How do I set this up so that the first box displays the user selected setting while also passing the $_POST information to the second box? My Code: <table> <tr> <td width=50%> Game Type: </td> <td width=50%> <form name='game_type' action='event_submit.php' method='post'> <select name='game_type' align=center onchange='this.form.submit()' style="width:150px;margin:5px 0 5px 0;"> <option value=''>Chose a Game Type</option> <option value='RPG'>RPG</option> <option value='LARP'>LARP</option> <option value='Board Game'>Board Game</option> <option value='CCG'>Collectable Cards & Games</option> <option value='Miniatures'>Miniatures</option> </select> </form> </td> </tr> <tr> <td width=50%> Game System: </td> <td width=50%> <?php $game_type = $_POST['game_type']; echo "$game_type"; if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DrowCon", $con); $result = mysql_query("SELECT * FROM Games WHERE Type='$game_type' ORDER BY System ASC"); echo "<form name='game_system' action='event_submit_form.php' method='post'>"; echo "<select name='game_system' align=center style='width:150px;margin:5px 0 5px 0;'>"; echo "<option value=''>Chose a Game System</option>"; while($row_game = mysql_fetch_array($result)) { echo "<option value=''>".$row_game['System']."</option>"; } echo "</form>"; mysql_close($con); ?> </td> </tr> </table> Hi I am trying to have the following as an example: Code: [Select] <select name="test[]" multiple="multiple">options here</select> <select name="test[]" multiple="multiple">options here</select> Then using $_POST['test'] to grab the boxes in the array. I want to then loop over each box so for example: Code: [Select] $boxes = $_POST['test']; foreach ( $boxes as $box ) // now here i would of expected $box to be an array of the options, } but it's not working like this, all the options from all submitted select boxes come in one array so I cannot distinguish which select box in the array they relate to, is there a way to do this?? Dear Support, Here is my code: <?php if ( strtolower($_SERVER['REQUEST_METHOD']) === 'post' ) { $name = isset($_POST['name]) ? htmlspecialchars($_POST['name']) : ""; $area = isset($_POST['area']) ? htmlspecialchars($_POST['area']) : ""; $choice = isset($_POST['choice ']) ? htmlspecialchars($_POST['choice ']) : ""; //Do Others } ?> <form class="customersForm" method="post"> <div class=""> <p>Name<br /> <select style="width:120px;" name="name"> <?php $sql = "select * from `name_info` order by `name`"; $query = mysql_query($sql); $dd = '<option>Name</option>'; while($row = mysql_fetch_object($query)) { $dd .= '<option>'.$row->name.'</option>'; } echo $dd; ?> </select> </p> </div> <div class=""> <p>Area<br /> <select style="width:120px;" area="area"> <?php $sql = "select * from `area_info` order by `area`"; $query = mysql_query($sql); $dd = '<option>Area</option>'; while($row = mysql_fetch_object($query)) { $dd .= '<option>'.$row->area.'</option>'; } echo $dd; ?> </select> </p> </div> <div class=""> <p>Choice<br /> <select style="width:120px;" choice="choice"> <?php $sql = "select * from `choice_info` where `name`='".$name."' and `area`='".$area."' order by `choice`"; $query = mysql_query($sql); $dd = '<option>Choice</option>'; while($row = mysql_fetch_object($query)) { $dd .= '<option>'.$row->choice.'</option>'; } echo $dd; ?> </select> </p> </div> ......//Others input fields ...some text fields ... </ form> I have the above code, where I would like to show the choice Drop-down box, depends on $name and $area match of the choice_info table. $name field and $area field needs to have any dependency and straight from the MySQL table. But, choice needs to depend on $name & $area. How can I do it without much using Javacript? I do not mind to use JavaScript, but prefer to minimal. By the way, I will have some other input fields too. It's an input form but, one drop-down box will be depends on two others choice. Thanks for your help. Hello, I have the following function function make_agent_drop($dropname,$parent=''){ $agents = mysql_query("SELECT * FROM ad_category WHERE cat_status='1' AND parent_id='".(is_numeric($parent)?$parent:"0")."'") or die(mysql_error()); $anum = mysql_num_rows($agents); if($anum>0){ $agentdrop='<select style="width:150px; height:20px; margin-left:100px; font-size:11px;" name="'.$dropname.'" id="'.$dropname.'" class="text" '.(is_numeric($parent)?'':'onchange="update_subcatdrop($(this).val());').'"> <option value="0">Select a Category</option>'; while($row= mysql_fetch_array($agents)){ $agentdrop.='<option value="'.$row['cat_id'].'">'.$row['cat_name'].'</option>'; } $agentdrop.='</select>'; }else{ $agentdrop= 'No '.(is_numeric($parent)?'Sub':'').'Categories Found.'; } return $agentdrop; ; } I creates a drop down from database cats and sub cats.. I am trying to figure out how to add a submit button to dynamically appear when it displays the sub category... Thanks! Dan Hi, I had a form which contains, 8 select boxes. In those 8 select boxes, 3 of the boxes are interlinked, like, I am able to generate data in other 2 select boxes, if one box is been selected. i.e. based upon selection of one select box, and i am able to generate data in other select box. So, 3 select boxes are interlinked. And remaining 5 selects are optional, if the user selects, then we need to generate data based upon selection of the user. Here the main issue is how to grab data in the post back form, like, how to capture the number of selects boxes selected and what are those selected, and based upon that we need to generate data. Here one more important thing is that, in the report generation form(postback form), I need to show the data in a table. So , in table I had 9 columns and these would be common to whatever the selection made, but, only the requeired data would be changed based upon the selection of the remaining 5 optional boxes. Hope you got me!!!! I need some help with the query for a form that selects values across multiple columns, and allow users to select multiple values in several columns. http://brinsterinc.com/tpa/tpasearch.php I assume you build the where clause for the sql by determining if there is an option value has been selected in the single-value select boxes. But how do I handle the multi-select list boxes? I'm desperate for help! Need to get somewhere with this over the weekend! TIA! 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. hirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks Hi Everyone, I am having problems when submitting a form that has check boxes within it (post.php). All the check boxes have a name and a checked value of 1 - the receiving page (for example submit.php) has the variables defined: $tickbox1 = $_POST['tickbox1']; The problem I am finding is that if the box isnt checked - I get an "index is not defined" error. I would suppose because there is no value. I have tried this before and it has worked, however that was on Apache and this is on IIS. Is there a work around? Thanks Matt I have a series of steps a user goes through to add a product. I'm having a problem with the first going to second page. The first page is a form to input information which has a "add" php file that goes with it that basically Posts and Inserts the information into the table, then moves on to the next page. It also auto increments a new id for the product in the table during this process. The problem is I'm trying to get the product id to carry over to the next page so they can review the information they just input. Any ideas on how I can pull that new id by going from that one page to the next with that move (Form>Insert(form action)>EditPage)? I'm just having a hard time visualizing this because I'm inserting the new product then there's nothing to reference because I can't pinpoint on the id yet. i need help with this issue.i designed a comment page where people can comment on a topic but what i descovered is that once i comment on a topic it will be showed on the page i asked it to go but if i comment on thesame topic it will not show exceeptb the one that as been there before.even if i click on anotherr topic and i comment once i cannot comment again but if i remove the WHERE clause all the comments meant for other topics will just display which is not good.Please help me thanks. this is my code: Code: [Select] <?php include"header.php"; $topicid=$_GET['id']; ///the two tables POST and TOPICS share thesame id $sql="SELECT post_comments FROM post WHERE $topicid=topicsID"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"{$row['post_comments']}"; } ?> Hi, i'm trying to select some entries from my DB, i don't quite understand what's the problem here, i'm using this: Code: [Select] //Customers Online $query = "SELECT COUNT(*) as Anzahl FROM customers WHERE status = 1"; $queryerg = mysql_query($query) OR die(mysql_error()); while($row = mysql_fetch_array($queryerg)){ $customers_online = $row[0]; } Which works fine, now i want to select by country and i'm doing this: Code: [Select] //Customers DE $query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de'"; $queryerg = mysql_query($query) OR die(mysql_error()); while($row = mysql_fetch_array($queryerg)){ $customers_de = $row[0]; } Which doesn't work? If i print / echo $customers_de i just get a blank value, not even 0 or anything just blank. Any help ? I have 5 entries in a table Code: [Select] $sql = "select count(distinct columnName) from table"; $result = mysql_result($sql); $count = mysql_fetch_array($result); echo $count[0];The output is 5 as expected. Code: [Select] $sql = "select distinct columnName from table"; $result = mysql_result($sql); $count = mysql_fetch_array($result); echo $count[0];the ouput is the first file name as expected, however Code: [Select] echo $count[1];gives undefined offset 1, which does not make any sense. Can anyone explain why the offset 1 is undefined if the count is 5? I want to make a list like this: I store the genres in a array like this: Code: [Select] $genre_list = array( array("ACTION", "First Person Shooter"), array("ACTION", "Third Person Shooter"), array("ACTION", "Tactical Shooter"), array("ACTION", "Fighting"), array("ACTION", "Arcade"), array("ADVENTURE", "Adventure"), array("ADVENTURE", "Platformer"), array("ADVENTURE", "Point and Click") ); This is my first attempt to only show the subgenre, i only get a blank list (apart from this <option value="genre">Genre</option> ). Code: [Select] <div class="forminput"> <select id="genres" name="genres"> <option value="genre">Genre</option> <?php for($i=0; $i<count($genre_list[0]); $i++) { ?> <option value="<?=$i?>"<?=$genre_list[0][$i]?></option> <?php } ?> </select> </div> I'm working on my website, and I'm having a bit of trouble in getting PHP to select the proper data. I'm trying to select usernames from my database where rank is equal to one (the highest, in my system). As such, I attempted this code; Code: [Select] // Connection info above this line... mysql_select_db("users"); $query = mysql_query ("SELECT displayname FROM login WHERE rank = 1"); $query_a = mysql_fetch_array($query); var_dump($query_a); The var_dump resulting from that is as follows; Code: [Select] array 0 => string 'Seltzer' (length=7) 'displayname' => string 'Seltzer' (length=7) Everything is working correctly, except for the fact that my database contains two displayname rows where rank is equal to one (EDIT: Two distinct rows). In fact, I can run a search of it in phpMyAdmin and get the two that my PHP code should be returning. phpMyAdmin generated the following query, which Inserted into my code in order to double-check things; Code: [Select] SELECT `displayname` FROM `login` WHERE `rank` =1 LIMIT 0 , 30 Even after I swapped my queries, the PHP code still returned the same var_dump as above. Complicating things further, I've noticed another function I've made, which queries "SELECT rank WHERE displayname = '$displayname'", functions perfectly. I've gotten rid of pretty much any source of the error I could think of; I'm testing the function on an otherwise empty page, I've removed any classes being used, and I've tried about a million different queries. Can someone help me out with this? I'm being held up by it and I'm sure that this is a simple fix. Thanks in advance, Dustin Hello everybody, I have a problem selecting rows from db. Copied error message: Quote Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\scriptforsite\index.php on line 223 I have searched for this problem, and I found tons of posts but I didn't do anything. Here is a code: Code: [Select] <?php include("include/functions.php"); db_connect(); lang_en(); lang_smiles(); lang_links(); $sql= mysql_query("SELECT msg_id,msg from messages order by msg_id desc"); while($row=mysql_fetch_array($sql)) { $msg=$row['msg']; $msg_id=$row['msg_id']; ?> <li class="bar<?php echo $msg_id; ?>"> <div align="left"> <span ><?php echo $msg; ?> </span> <span class="delete_button"><a href="#" id="<?php echo $msg_id; ?>" class="delete_update">X</a></span> </div> </li> <?php } db_close(); ?> This line 223 is this: $sql= mysql_query("SELECT msg_id,msg from messages order by msg_id desc"); ... I have tried to replace msg_id,msg with * but on this way I don't have dump from table... Hi, I'm a little bit new to php and i'm having a small problem. Let me explain with the script : Code: [Select] <?php //connect to mysql $data = mysql_query("SELECT * FROM forum_topic WHERE topic_id='$topic'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) $dete = mysql_query("SELECT * FROM forum_topic WHERE login='$info['username']'") or die(mysql_error()); while($info2 = mysql_fetch_array( $dete )) { echo "......"; } ?> So I have the first SELECT command that will get the data from table forum_topic and array the data and after that I have a second SELECT that will get the data from table_members but this time time the WHERE clause equals to some data "arrayed" in the first SELECT command...And the end I need to output the data from both tables.... Here's the error I get : Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/m/a/z/mazemontana/html/login/forum_viewtopic.php on line 73 ...I know that my syntax is probably not good but can't figure out how to do it..... Any help will be greatly appreciated! Thanx Hi.. I got problem in logic on my problem in select option. Here is my scenario. I have select option which has a compound list: example: P28 P30 P32 P33 P35 and I have tables which has a total count of compound that was already transact. for example I already transact 10 P28 compound. it will save in kanban_checker table field Total. and I have parameter_settings table which has the maximum and minimum per compound: fields----------data P28------------P28 P28_max-----10 P28_min------6 P30------------P28 P30_max-----10 P30_min------6 P32------------P28 P32_max-----10 P32_min------6 P33------------P28 P33_max-----10 P33_min------6 now the logic is: if P28 total = P28_max then notify that he already reach the maximum..it will not produce P28 because he already reach the maximum. if P28 total = P28_min then produce P28. same with other compound. Now, I got a problem in coding and logic, because in the select option I'm not the one who code it.. I just one who need to add the additional function.. here is the code for select option and the function that was created by other, Code: [Select] $smarty->assign('text_name1','Compound Code'); $smarty->assign('compoundIndexValue', array('0', 'P28', 'P30', 'P32', 'P33', 'P35', 'P35M', 'P38', 'P40', 'P41', 'P42', 'P43', 'P46', 'P47', 'PXX', 'P35W')); <tr> <td class="tdMainText">{$text_name1}</td> <td> <select class="tdMainElement" id="selCompound" onchange="isSelected('selCompound','txtLotCode')" onclick="clearNotify()" onblur="this.focus();" onkeypress="return false">{html_options values=$compoundIndexValue output=$names selected="0"} </select> </td> </tr> <script type="text/javascript"> function isSelected(obj1, obj2) { if (!document.getElementById(obj1).disabled) { document.getElementById(obj1).disabled = true; } if (document.getElementById('clear').disabled) { document.getElementById('clear').disabled = false; //enable it } if ((document.getElementById('chkDownGrade') != null)) { if (!document.getElementById('chkDownGrade').disabled) { document.getElementById('chkDownGrade').disabled = true; } } if (document.getElementById(obj2).disabled) { document.getElementById(obj2).disabled = false; } document.getElementById(obj2).focus(); document.getElementById(obj2).focus(); //notify("Gain Maximum Total"); } function disable() { if (!document.getElementById('clear').disabled) { document.getElementById('clear').disabled = true; } else { document.getElementById('clear').disabled = false; } } function clearNotify() { if (document.getElementById('notice') != null) { document.getElementsByTagName('body')[0].removeChild(document.getElementById('notice')) //>> clear the box } } </script> and here is the code that I tried to add: Code: [Select] $compound = mysql_real_escape_string($_POST['compound']); $sql = "SELECT P28, P28_max, P28_min, P30, P30_max, P30_min, P32, P32_max, P32_min, P33, P33_max, P33_min, P35, P35_max, P35_min, P35M, P35M_max, P35M_min, P35W, P35W_max, P35W_min, P38, P38_max, P38_min, P41, P41_max, P41_min, P42, P42_max, P42_min, P43, P43_max, P43_min, P46, P46_max, P46_min FROM parameter_settings"; $res_pcode = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_pcode)){ $P28 = $row['P28']; $P28_max = $row['P28_max']; $P28_min = $row['P28_min']; $P30 = $row['P30']; $P30_max = $row['P30_max']; $P30_min = $row['P30_min']; $P32 = $row['P32']; $P32_max = $row['P32_max']; $P32_min = $row['P32_min']; $P33 = $row['P33']; $P33_max = $row['P33_max']; $P33_min = $row['P33_min']; $P35 = $row['P35']; $P35_max = $row['P35_max']; $P35_min = $row['P35_min']; $P35M = $row['P35M']; $P35M_max = $row['P35M_max']; $P35M_min = $row['P35M_min']; $P35W = $row['P35W']; $P35W_max = $row['P35W_max']; $P35W_min = $row['P35W_min']; $P38 = $row['P38']; $P38_max = $row['P38_max']; $P38_min = $row['P38_min']; $P41 = $row['P41']; $P41_max = $row['P41_max']; $P41_min = $row['P41_min']; $P42 = $row['P42']; $P42_max = $row['P42_max']; $P42_min = $row['P42_min']; $P43 = $row['P43']; $P43_max = $row['P43_max']; $P43_min = $row['P43_min']; $P46 = $row['P46']; $P46_max = $row['P46_max']; $P46_min = $row['P46_min']; $P47 = $row['P47']; $P47_max = $row['P47_max']; $P47_min = $row['P47_min']; } // $sub_lotcode = substr($lotCode, 9, 4); $sql = "SELECT PCODE, total FROM kanba_checker WHERE PCODE = '$sub_lotcode' ORDER BY PCODE"; $res_kanban = mysql_query($sql, $con); $row_kanban = mysql_fetch_assoc($res_kanban); $PCODE = $row_kanban['PCODE']; $total = $row_kanban['total']; if($compound = $P28 || $total == $P28_max){ echo "<script type='text/javascript'>alert(P28 gain total maximum)</script>"; } else{ } but I don't know if my code and my logic is correct. I think I did to add function. But I don't know how.. I hope someone can help me or guide me to solve my problem. Thank you so much.. I have got a set of data for a country for each week of the year, but want to display the data a quarter at a time, using a form which posts a value into LIMIT, which was OK for the 1st quarter, but for subsequent quarters I needed to use LIMIT in the form LIMIT start, rows.
I found by experiment that this had to be the last statement in the query.
when I added the start I got an error:
Parse error: syntax error, unexpected ',' in /homepages/43/d344817611/htdocs/Admin/Visitdata.php on line 10
Here is the SQL part of my code:
$Visit_data="SELECT WeekNo.WNo, WeekNo.WCom, Countries.Country, ctryvisits.CVisits FROM ctryvisits LEFT JOIN Countries ON ctryvisits.country=Countries.CID LEFT JOIN WeekNo ON ctryvisits.WNo=WeekNo.WNo WHERE Countries.Country = '".$_POST["Country"]."' ORDER BY ctryvisits.WNo LIMIT '".$_POST["QUARTER"]."'" - 13, '".$_POST["QUARTER"]."'";Is this the best way of doing what I require or is there an easier way of achieving what I want? |