Auto submit Combobox display information from the database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seven
    New Member
    • Mar 2013
    • 1

    Auto submit Combobox display information from the database

    Hi.. I'am encountering a problem with this code.
    Code:
    <form method="post" action="http://bytes.com/jf.php"> <select name="category" onchange="this.form.submit()"> <option value="" selected>Select a category</option> <?php
            mysql_connect("localhost","root","");
            mysql_select_db("test");
            $category = "SELECT * FROM achievercollege";
            $query_result = mysql_query($category);
            while($result = mysql_fetch_assoc($query_result))
            {
            ?> <option value = "<?php echo $result['id']?>"><?php echo $result['id']?></option> <?php
    			
    			
            } 
    		
    		
        ?> <?php 
    
      mysql_connect("localhost","root","");
            mysql_select_db("test");
    
    $query = "SELECT * FROM achievercollege where id = '".$_POST['category']."'";
    $result = mysql_query($query);
    
    if (!$result) die ("Database access failed: " . mysql_error());
    $rows = mysql_num_rows($result);   ?> <?php 
    	 $row = $rows;
    for ($j=0;$j<$row;++$j){
       $rows=mysql_fetch_row($result);
    	
    ?> <?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
            mysql_connect("localhost","root","");
            mysql_select_db("test");
            $category = "SELECT * FROM achievercollege";
            $query_result = mysql_query($category);
            while($result = mysql_fetch_assoc($query_result))
            {
            ?> <option value = "<?php echo $result['id']?>"><?php echo $result['id']?></option> <?php
    			
    			
            } 
    		
    		
        ?> <?php 
    
      mysql_connect("localhost","root","");
            mysql_select_db("test");
    
    $query = "SELECT * FROM achievercollege where id = '".$_POST['jean']."'";
    $result = mysql_query($query);
    
    if (!$result) die ("Database access failed: " . mysql_error());
    $rows = mysql_num_rows($result);   ?> <?php 
    	 $row = $rows;
    for ($j=0;$j<$row;++$j){
       $rows=mysql_fetch_row($result);
    	
    ?> <?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
    Last edited by Dormilich; Mar 13 '13, 11:02 AM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    Working...