January 26th, 2013, 07:16 PM
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.
I am not geting it to work as expected and no errors generated.
<select name="cobjecttype" id="cobjecttype" tabindex="" >
<option value="">---Select object type---</option>
<option value="cgold">Gold and silverware</option>
I will appreciate.
January 26th, 2013, 07:58 PM
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.
January 26th, 2013, 07:59 PM
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?