如果错误情况如何拆分 - php

我有一些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来回显不同的错误消息?

参考方案

//and check
if ($postvalue > $minimumpostvalue) { //check exception
   echo "Error 1."; 
} elseif ($postvalue == '' || $postvalue <= 0 || $postvalue == is_int($postvalue)) { //check the rest
      echo "Error 2."; 
} //checkpost ends.

PHP:获取调用引用的数组名称 - php

假定以下函数并调用:function doSomething( &$someArray ) { // Do something to $someArray } $names=array("John", "Paul", "George", "Ringo"); doSomet…

PHP If / Else语句在While循环中不起作用 - php

我已经花了大约一个小时的时间来研究这段代码,似乎无法弄清为什么它不起作用。 PHP是否在While循环中允许If / Else语句?我尝试向If / Else语句添加不同的回显,并且后者(Else)将不会显示。这是因为我试图使用相同的变量名吗?while($row = mysql_fetch_array($result)) { //assign variab…

PHP-MySQL结果转换为JSON - php

我试图了解如何将MySQL结果转换为JSON格式,以便以后可以在Javascript中使用此JSON来构建HTML表。但是我的代码只是产生大量的空值,我还不明白为什么。$result = mysqli_query($con, "SELECT * FROM Customers"); $test = json_encode($result);…

PHP Count数组元素 - php

嗨,有人可以解释为什么这会返回“数组由0个元素组成”。 :$arr = array(1,3,5); $count = count($arr); if ($count = 0) { echo "An array is empty."; } else { echo "An array has $count elements.…

PHP:从函数返回值并直接回显它? - php

这可能是一个愚蠢的问题,但是……的PHPfunction get_info() { $something = "test"; return $something; } html<div class="test"><?php echo get_info(); ?></div> 有没有办…