1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Rep Power

    HTML Select Option to add data


    I am developing an online gallery for one of our local museum. I am new to PHP scripting and so I have numerous challenges. At this point I would like to understand how I can add data from html select option values into a mysql field.

    <select name="cobjecttype" id="cobjecttype" tabindex="" >
    			<option value="">---Select object type---</option>
    			<option value="cceramic">Ceramic</option>
    			<option value="cclock">Clock</option>
    			<option value="cgold">Gold and silverware</option>
    			<option value="cmask">Mask</option>
    			<option value="cpainting">Painting</option>
    			<option value="csculpture">Sculpture</option>
    			<option value="ctapestry">Tapestry</option>
    I am not geting it to work as expected and no errors generated.

    I will appreciate.

  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Rep Power
    There's no problem with your <select> element that I see. The value will be submitted to your PHP script in either $_POST['cobjecttype'] or $_GET['cobjecttype']. From there, you need to construct and run an appropriate insert or update query depending on what exactly you want to do with that piece of data.

    The issue you're running into is more likely with your PHP code than your HTML.

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    The name of the input is "cobjecttype" so the selected value will be either $_POST["cobjecttype"] (if your form is action=post) or $_GET["cobjecttype"] (otherwise).
    For the database follow a generic PHP+MySQL tutorial, but look for one using mysqli or PDO - not the regular mysql extension and its mysql_* functions.

    Sounds like you have more code than you've shown so far. What is it?

IMN logo majestic logo threadwatch logo seochat tools logo