Here’s the html structure:
<select name="marke" class="marke">
<option value="1">Bosch</option></select>
<select name="modell" class="modell">
<option value="2">Nocria 14 LBC</option></select>
Here is my Php string (simplified)
$modellz = $_POST['marke']. ' ' .$_POST['modell'];
$insertQuery = "INSERT INTO producz (model)
VALUES
('" . $modellz . "')";
Im trying to get the name inside the <option> – tag to Post into the database.
But with this code I just get the values.
So when i run this i get 1 2 in the database.
But I want Bosch Nocria 14 LBC
OBS: I NEED THE VALUE attribute for my jquery selection script.
Please help!
The issue is with the HTML. The
valuefor each<option>tag is what’s sent in the POST request.Change the HTML to:
and you will see the results you desire.
Also, please validate/sanitize your form-input before saving into the database. If you’re using mysql functions, try
mysql_real_escape_string().If jQuery needs access to the original ID for each option, I would suggest one of two methods. Either add a separate attribute to each option, such as rel:
<option value="Bosch" rel="1">Bosch</option>, or keep your code as-is (<option value="1">Bosch</option>) and have PHP aware of the ID/value combinations.The actual database-structure could, and possibly should, modified to support the actual IDs instead of textual values.