Results 1 to 2 of 2

Thread: dropdown list get selected value into mysql table

  1. #1
    Join Date
    Jun 2008
    Posts
    121
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default dropdown list get selected value into mysql table

    hi all

    in my database i have two tables. one is dealer_table, and other is category_table.
    i want to insert dealer name,dealer logo and category_id in dealer_table.
    Dealer name and dealer logo will be entered from dealer_table and category_id will be entered from category_table.
    i have used script to fetch that category id from category_table into the <select> dropdown options. that is working fine.

    now what should i insert in my script that will allow me to select the category_id depending upon the selected option from dropdown and get its selected value in dealer_table.


    <?php
    require_once("../config.php");
    $msg="";

    if(isset($_REQUEST['submit']))
    {
    $dealer_name=$_REQUEST['dealer_name'];
    $path=$_FILES['dealer_logo']['name'];
    move_uploaded_file($_FILES['dealer_logo']['tmp_name'], "uploads/" . $_FILES['dealer_logo']['name']);

    $qry="insert into dealer_table(dealer_name,category_id,dealer_logo) values('$dealer_name', '$path')";

    if(mysql_query($qry))
    $msg="Dealer Inserted successfully";
    else
    $msg="Error Inserting dealer";
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <table width="901" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td><form action="" method="post" enctype="multipart/form-data" name="form1">
    <table width="400" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td height="30" colspan="3" class="heading_green">Add New Dealer </td>
    </tr>
    <tr>
    <td height="50" colspan="3" align="center" style="border-bottom:1px dotted #CCCC33;border-top:1px dotted #CCCC33">Choose the category for dealer <br />
    <select name="select">
    <option>select category</option>
    <?php
    $sql = "SELECT category_id, category_name FROM category_table ";

    $rs = mysql_query($sql);

    while($row = mysql_fetch_array($rs))
    {
    echo "<option value=\"".$row['category_id']."\">".$row['category_name']."\n ";
    }
    ?>
    </select></td>
    </tr>
    <tr>
    <td colspan="3" style="color:#FF0000"><?php echo $msg;?></td>
    </tr>
    <tr>
    <td width="25%" height="30">Dealer name : </td>
    <td width="2%" height="30">&nbsp;</td>
    <td width="73%" height="30"><input type="text" name="dealer_name" id="dealer_name" /></td>
    </tr>
    <tr>
    <td height="30">Dealer Logo : </td>
    <td height="30">&nbsp;</td>
    <td height="30"><input type="file" name="dealer_logo" id="dealer_logo" /></td>
    </tr>
    <tr>
    <td height="30">&nbsp;</td>
    <td height="30">&nbsp;</td>
    <td height="30"><input type="submit" name="submit" id="submit" value="Add Dealer" /></td>
    </tr>
    </table>
    </form></td>
    </tr>
    </table>
    </body>
    </html>

  2. #2
    Join Date
    Sep 2008
    Posts
    56
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default

    Hi,

    To access the value of category id selected you can use $HTTP_POST_VARS["select"], where "select" is the name of the drop down.

    Hope this helps!

    Cheers,

    ~Maneet
    LeXolution IT Services
    Web Design Services

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •