how to insert values from combo box into mysql table

Discussion in 'Programming/Scripts' started by abc, Nov 22, 2010.

  1. abc

    abc New Member

    I have made a combo box in dreamweaver using php.After selecting any of the field from the combo box the user writes his topic in text box related to that particular field.In mysql i have made separate tables of every field mentioned in combo box.Now i wnat that whenever user press the submit button after selecting the field from combo box the topic he writes in the textbox is inserted to that relevent table for example if networking field is selected then the topic in text box should be saved in the networking table in database.I am posting the code.Any kind of help will be appreciated.
    Code:
    <form name=myform>
      
      <table width="75%" border="1">
        <tr>
          <td width="28%" valign="top"><p>Choose any field: </p>
            
    </td>
          <td width="72%" valign="top"><p>
              <select name=mytextarea>
                <option name=Website development value=website> website development 
                </option>
                <option name=networking value=networking > networking </option>
                <option name=databases value=databases> databases </option>
              </select>
            </p>
            </td>
        </tr>
        <tr>
          <td>Enter your topic related to field: 
           
          </td>
          <td><input name="topic" type="text" id="topic4"></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input name="submit" type="submit" id="submit3" value="Submit"></td>
        </tr>
      </table>
     
      </form>
    
    
    
    
    
     
  2. falko

    falko Super Moderator Howtoforge Staff

    Try something like

    PHP:
    if($mytextarea){
      foreach(
    $mytextarea as $option){
        
    $sql "INSERT INTO ".$option." ..."// This assumes that your database tables are named exactly like the values from the <option> value fields. Make sure you complete the SQL statement.
        // Now fill in your PHP code to execute the MySQL query.
        
    ....
      }
    }
     
  3. abc

    abc New Member

    Thanks a lot
     
  4. abc

    abc New Member

    thanks a lot
     

Share This Page