本文介绍了如何从< datalist>的选项中获取项目在PHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$_POST在数据库中返回空值.为什么会这样?

$_POST return null value in the database. Why does this happen?

<datalist name="countries" class="form-control">
    <option value="India">India</option>
    <option value="United States">United States</option>
    <option value="United Kingdom">United Kingdom</option>
    <option value="Germany">Germany</option>
    <option value="France">France</option>
</datalist>

<?php
if (isset($_POST['countries'])){
   $country=$_POST['countries']; 
}else{
    echo 'no value';
}
?>

推荐答案

这只是常规表单提交.

<?php

if(isset($_POST['submit'])) {
    $country = $_POST['countries'];
    echo $country;
}

?>

<form method="POST">
    <input list="countries" name="countries" />
    <datalist id="countries">
        <option value="India">India</option>
        <option value="United States">United States</option>
        <option value="United Kingdom">United Kingdom</option> 
        <option value="Germany">Germany</option> 
        <option value="France">France</option> 
    </datalist>
    <input type="submit" name="submit" />
</form>

这篇关于如何从&lt; datalist&gt;的选项中获取项目在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 23:28