我有一个带有下拉菜单的HTML表单,用于选择使用PHP从MySQL数据库动态填充的名称。我将如何通过表单提交该值或所选名称?
这是我的下拉菜单:
<select class="form-control" name="nameselect" required>
<option value="" disabled selected>Select Name</option>
<?php while($row1 = mysqli_fetch_array($result1)):?>
<option value="<?php echo ($row1["fullname"]);?>"><?php echo ($row1["fullname"]);?></option>
<?php endwhile;?>
</select>
答案 0 :(得分:0)
//first check if it's selected
if(isset($_POST['save']) && isset($_POST['nameselect'])){
$name=$_POST['nameselect'];
//using mysqli prepared statement
$result=$con->prepare("INSERT INTO tablename VALUES(?, ? )") ; //query
if ($result){ //if query
$result->bind_param('ss', $name, $anyothervalue ); //bind the parameters
$result->execute(); //execute the query
}
if($result->affected_rows >0){ //if data is inserted
echo "Added Successfully!!!"; //success message
}
else{
echo "error"; //error message
}
希望这会有所帮助