我用簡單的驗證PHP程序的工作,我有2個文件,1個用於顯示和1個控制這些都是我的代碼:總是返回一個聲明
<form action="comp.php" method="post">
<input type="text" name="reading" placeholder="kilometer reading">
<input type="date" name="date1" placeholder="date">
<input type="text" name="suggest" placeholder="suggested kilometer">
<input type="text" name="part" placeholder="spare part">
<input type="submit" class="button" name="btnsubmit" value="Submit">
</form>
,這是對我的控制:
$date1 = date('Y-m-d', strtotime($_POST['date1']));
$reading = $_POST['reading'];
$suggest = $_POST['suggest'];
$part =$_POST['part'];
$sql = "SELECT reading FROM sched ORDER BY reading DESC LIMIT 1";
$result = mysqli_query($sqli, $sql);
if (empty($_POST['reading']))
{
echo "No Input ";
exit;
}
elseif ($_POST['reading'] < $result)
{
echo "Must input higher value than";
exit;
}
elseif ($_POST['reading'] > $result)
{
if (($_POST['date1']) == "1970-01-01")
{
echo "no date input";
exit;
}
else
{
$query = mysqli_query($sqli,"INSERT INTO sched (date,reading,suggest,part) VALUES ('$date1','$reading','$suggest','$part')");
}
}
}
mysqli_close($sqli);
header("Location: log.php");
我目前的最高讀數是'15000'。 當我的字段reading
爲空時,程序可以正常工作,但是如果我向我的字段輸入值,即使輸入的值高於15000,也總是返回echo "Must input higher value than"; exit;
.這是什麼問題?
如果您嘗試獲取結果集,將更好地工作,目前'$ result'將等於或者TRUE;或'false'作爲mysqli_query()返回查詢執行的狀態,而不是返回結果集。當所有其他都失敗時[閱讀Flippin手冊](http://php.net/manual/en/function.mysql-query.php) – RiggsFolly
使用提示信息的錯誤消息是非常好的做法,以'echo'開始您的輸入值['。$ _ POST ['reading']。']低於['.result。']';' –