By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,969 Members | 1,735 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,969 IT Pros & Developers. It's quick & easy.

Auto submit Combobox display information from the database

P: 1
Hi.. I'am encountering a problem with this code.
Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="http://bytes.com/jf.php"> <select name="category" onchange="this.form.submit()"> <option value="" selected>Select a category</option> <?php
  2.         mysql_connect("localhost","root","");
  3.         mysql_select_db("test");
  4.         $category = "SELECT * FROM achievercollege";
  5.         $query_result = mysql_query($category);
  6.         while($result = mysql_fetch_assoc($query_result))
  7.         {
  8.         ?> <option value = "<?php echo $result['id']?>"><?php echo $result['id']?></option> <?php
  9.  
  10.  
  11.         } 
  12.  
  13.  
  14.     ?> <?php 
  15.  
  16.   mysql_connect("localhost","root","");
  17.         mysql_select_db("test");
  18.  
  19. $query = "SELECT * FROM achievercollege where id = '".$_POST['category']."'";
  20. $result = mysql_query($query);
  21.  
  22. if (!$result) die ("Database access failed: " . mysql_error());
  23. $rows = mysql_num_rows($result);   ?> <?php 
  24.      $row = $rows;
  25. for ($j=0;$j<$row;++$j){
  26.    $rows=mysql_fetch_row($result);
  27.  
  28. ?> <?php };?> </select> <input type="text" value="<?php echo $rows[1]; ?>" /> <td>*</td> <input type="text" value="<?php echo $rows[2]; ?>" /> <td>*</td> <input type="text" value="<?php echo $rows[3]; ?>" /> <select name="jean" onchange="this.form.submit(1)"> <option value="" selected>Select a category</option> <?php
  29.         mysql_connect("localhost","root","");
  30.         mysql_select_db("test");
  31.         $category = "SELECT * FROM achievercollege";
  32.         $query_result = mysql_query($category);
  33.         while($result = mysql_fetch_assoc($query_result))
  34.         {
  35.         ?> <option value = "<?php echo $result['id']?>"><?php echo $result['id']?></option> <?php
  36.  
  37.  
  38.         } 
  39.  
  40.  
  41.     ?> <?php 
  42.  
  43.   mysql_connect("localhost","root","");
  44.         mysql_select_db("test");
  45.  
  46. $query = "SELECT * FROM achievercollege where id = '".$_POST['jean']."'";
  47. $result = mysql_query($query);
  48.  
  49. if (!$result) die ("Database access failed: " . mysql_error());
  50. $rows = mysql_num_rows($result);   ?> <?php 
  51.      $row = $rows;
  52. for ($j=0;$j<$row;++$j){
  53.    $rows=mysql_fetch_row($result);
  54.  
  55. ?> <?php };?> </select> <input type="text" value="<?php echo $rows[1]; ?>" /> <td>*</td> <input type="text" value="<?php echo $rows[2]; ?>" /> <td>*</td> <input type="text" value="<?php echo $rows[3]; ?>" /> </form>

I have combo boxes that submits information once an item was selected. The information I needed, correctly displayed on the screen but the problem is when I add another combobox the information on the first combox doesn't show. I can't figure out the problem. Can someone help me with this? Any suggestion or help will always be appreciated.
Thanks,
Seven
Mar 13 '13 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
You will need to pass this information to the posted page, otherwise the PHP code has no knowledge of any changes to the page after being loaded.

One way would be to set the combo box selected option from the $_POST value.

Another option is to use Ajax to avoid reloading the page on submit and simply add the combo box for the category selected.
Mar 13 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.