gpt4 book ai didi

php - 如何拆分 if else 错误条件

转载 作者:行者123 更新时间:2023-12-02 08:42:06 26 4
gpt4 key购买 nike

我使用一些 if/else 语句进行了验证。

<?php
if (isset($_POST["join"])) {

if ($userpoint < $lessonpoint) { //pt
echo "you need more points";
} //pt

else { //has enough point


if ($row['num'] > 0) { //check if user took this lesson
echo "you took this lesson before.";
} //check if user took this lesson ends


else { //then let him apply to database

//define post:
$postvalue = (int)$_POST["postvalue"];

//and check
if($postvalue == '' || $postvalue <= 0 || $postvalue > $minimumpostvalue || $postvalue == is_int($postvalue)) { //check post
echo "Error.";

} //checkpost ends.


else { //insert

$sql = "INSERT into etc... VALUES (?, ?, ?)";

if($sql){ //to another database

$artibir = "UPDATE etc.";

echo "Done.";

} // to another database
}//insert
} //let him apply
} //has enough point
} //if post isset join
?>

这非常有效。

但我想针对这种情况回显另一条错误消息:$postvalue > $minimumpostvalue

在尝试时,我迷失在 if/else 语句中。无论我在哪里放置新语句,我都会遇到错误。

所有变量均已定义。

在哪里以及如何放置 $postvalue > $minimumpostvalue 来回显不同的错误消息?

最佳答案

<?php
if (isset($_POST["join"])) {

if ($userpoint < $lessonpoint) { //pt
echo "you need more points";
} //pt

else { //has enough point

if ($row['num'] > 0) { //check if user took this lesson
echo "you took this lesson before.";
} //check if user took this lesson ends

else { //then let him apply to database

//define post:
$postvalue = (int) $_POST["postvalue"];

//and check
if ($postvalue == '' || $postvalue <= 0 || $postvalue > $minimumpostvalue || $postvalue == is_int($postvalue)) { //check post
if ($postvalue > $minimumpostvalue) {
echo "Another Error.";
}
else {
echo "Error.";
}

} //checkpost ends.

else { //insert

$sql = "INSERT into etc... VALUES (?, ?, ?)";

if ($sql) { //to another database

$artibir = "UPDATE etc.";

echo "Done.";

} // to another database
} //insert
} //let him apply
} //has enough point
} //if post isset join
?>

关于php - 如何拆分 if else 错误条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34345973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com