Php MySQL只存储“1”(作为一个值),无论我在表单中提交什么数字

Php MySQL只存储“1”(作为一个值),无论我在表单中提交什么数字,php,mysql,forms,twitter-bootstrap,submit,Php,Mysql,Forms,Twitter Bootstrap,Submit,我正在尝试用php和mysql创建一个简单的引导表单,我使用带有默认设置的xampp。所有操作都在一个名为index.php的文件中完成 这是我的表格: <form class="form-horizontal" role="form" method="post" action="index.php" > <div class="form-group"> <label for="inputLon

我正在尝试用php和mysql创建一个简单的引导表单,我使用带有默认设置的xampp。所有操作都在一个名为index.php的文件中完成

这是我的表格:

<form class="form-horizontal" role="form" method="post" action="index.php" >
                <div class="form-group">
                    <label for="inputLongitude" class="col-lg-2 control-label">Longitude</label>
                    <div class="col-lg-10">
                      <input type="number" class="form-control" id="inputLongitude" placeholder="longitude" name="inputLongitude">
                    </div>
                </div>
                <div class="form-group">
                    <label for="inputLatitude" class="col-lg-2 control-label">Latitude</label>
                    <div class="col-lg-10">
                      <input type="number" class="form-control" id="inputLatitude" placeholder="latitude" name="inputLatitude">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-lg-offset-2 col-lg-10">
                      <button type="submit" name="submit" class="btn btn-primary">Save</button>
                    </div>
                </div>
                               </form>
到目前为止,几乎一切都很好。将保存这两个值。 以下是我的db设置:

现在我的问题是:应该保存的值=我要提交并存储在db中的值没有存储。因此,与存储(例如50)不同,5 mysql只存储1-始终,无论我以何种形式发送。看看这里


真正有趣的是,如果我在phpmyadmin中使用SQL并以手动方式在其中插入值,它就可以了。没问题。你知道我怎么解决这个问题吗?我的数据库设置错误吗?或者它在代码中的某个地方

您正在使用isset函数

$longti = isset($_POST['inputLongitude']);
上面的代码没有设置$\u POST['InputLength']的值,而是设置$\u POST['InputLength']是否存在。。。1意味着它存在

您可以简单地使用:

$longti = $_POST['inputLongitude'];
这始终是0或1:isset或not。如果isset blah=someotherblah,则使用此选项

if (isset($_POST["inputLatitude"])) {
    $lati = $_POST['inputLatitude'];  
}else{  
    echo "N0, inputLatitude is not set";
}

您的问题出现在以下位置:

$longti = isset($_POST['inputLongitude']); 
$lati = isset($_POST['inputLatitude']);
此块正在分配isset的真值。。。改为$longti和$lati,而不是您从$\u POST获得的预期值。如果您完全确信这些$u POST值的安全性,而您不应该这样做,那么您应该:

$longti = isset($_POST['inputLongitude']) ? $_POST['inputLongitude'] : null; 
$lati = isset($_POST['inputLatitude']) ? $_POST['inputLatitude'] : null;
如果这些值像$u POST值通常一样来自不受信任的来源,那么在将它们输出到数据库之前,您还应该对这些值执行一些验证

编辑:我刚刚注意到$out=isset$in$in:空;模式看起来是多余的:$out=$in;将执行完全相同的操作。我通常会在这一步中包括基本的验证/过滤。例如,如果由于您的类型为“numeric”,所以您所期望/允许的只是一个数值:

$longti = isset($_POST['inputLongitude']) && is_numeric($_POST['inputLongitude'])
    ? $_POST['inputLongitude'] : null;
或仅限整数:

$longti = isset($_POST['inputLongitude']) ? (int) $_POST['inputLongitude'] : null;

这些都是简单的例子,不包括对无效表单内容等用户的反馈。

Oh man。是的,很有效,非常感谢。我会投赞成票,可惜不能。顺便说一句,我忘了提到我是php+mysql的初学者。但我当然会将其标记为已解决。实际上,您至少应该使用mysqli_real_escape_string对进入SQL字符串的值进行转义,或者使用准备好的语句。
$longti = isset($_POST['inputLongitude']) && is_numeric($_POST['inputLongitude'])
    ? $_POST['inputLongitude'] : null;
$longti = isset($_POST['inputLongitude']) ? (int) $_POST['inputLongitude'] : null;