Use jquery to add the drop down. The option value is from mysql database. It is included as getItems.php. Then, submit the selected value to mysql. It occurs the SyntaxError. It seems the php syntax is invalid in jquery. The included part cannot be shown on one row.
jquery:
<script>
$(function() {
$('#add').click(function(){
var item = '<div class="form-group"><label class="col-sm-2 control-label">Item</label><div class="col-sm-10"><select class="form-control" name="item"><?php include 'getItems.php'; ?></select></div></div>';
// error
$('#addItem').append(item);
});
});
</script>
php:
$query = "SELECT itemName FROM Item";
$results = mysql_query($query);
if (!$results) {
die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_array($results)) {
echo '<option>'.$row["itemName"].'</option>';
}
error:
Uncaught SyntaxError: Invalid or unexpected token
console:
var item = '<div class="form-group"><label class="col-sm-2 control-label">Item</label><div class="col-sm-10"><select class="form-control" name="item"> <option>Item1</option><option>Item2</option><option>Item3</option>
</select></div></div>';
Last edit: change the var item = $('') to var item = ''. But it still has the same error.