简体   繁体   English

我收到警告:计数():参数错误

[英]I am getting Warning:count():Parameter error

I am getting this error below in my vehicles-update.php and I have also attached my vehicle/index.PHP code.我在下面的车辆更新中收到此错误。php 并且我还附上了我的车辆/索引。PHP 代码。 It appears before my header on my phpmotors/index.php page.它出现在我的 phpmotors/index.php 页面上的 header 之前。

Warning: count(): Parameter must be an array or an object that implements Countable in C:\xammp_124\htdocs\phpmotors\vehicles\index.php on line 142 Error shown: if(count($invInfo)<1){ Warning: count(): Parameter must be an array or an object that implements Countable in C:\xammp_124\htdocs\phpmotors\vehicles\index.php on line 142 Error shown: if(count($invInfo)<1){

<?php
/***********************************************
 * Vehicles  Controller
 *********************************************/

// Create or access a Session
session_start();

// Get the database connection file
require_once '../library/connections.php';
// Get the database connection file
require_once '../library/functions.php';
// Get the PHP Motors model for use as needed
require_once '../model/main-model.php';
// Get the accounts model
// require_once '../model/classification-model.php';
// Get the accounts model
require_once '../model/vehicles-model.php';


 // Get the array of classifications
 $classifications = getClassifications();

// var_dump($classifications);
// exit;
// Build a navigation bar using the $classifications array
 $navList = '<ul>';
 $navList .= "<li><a href='/index.php' title='View the PHP Motors home page'>Home</a></li>";
 foreach ($classifications as $classification) {
  $navList .= "<li> <a href='/vehicles/?action=classification&classificationName="
    .urlencode($classification['classificationName']).
    "' title='View our $classification[classificationName] lineup of vehicles'>$classification[classificationName]</a> </li>";
 }
 $navList .= '</ul>';

 $action = filter_input(INPUT_GET, 'action');
 if($action == NULL) {
     $action = filter_input(INPUT_POST, 'action');
 }

 switch ($action) {
    case 'add-classification':
      if (isset($_SESSION['loggedin']) && $_SESSION['clientData']['clientLevel']>1){
        include '../view/add-classification.php';
      } else {
       header('Location: /index.php');
      }
      break;
      
    case 'add-vehicle':
      if (isset($_SESSION['loggedin']) && $_SESSION['clientData']['clientLevel']>1){
        include '../view/vehicles-update.php';
      } else {
       header('Location: /index.php');
      }
      break;

    case 'adding-classification':
        // Filter and store the data
        $classificationName = filter_input(INPUT_POST, 'classificationName', FILTER_SANITIZE_STRING);
      // Check for missing data
      if(empty($classificationName)){
        $message = '<p>Please provide information for all empty form fields.</p>';
        include '../view/add-classification.php';
        exit;
      }
      
      // Send the data to the model
      $regOutcome = regClassification($classificationName);
      
      // Check and report the result
      if($regOutcome === 1){
        $message = "<p>Thanks for registering $classificationName.</p>";
        // Get the array of classifications
        $classifications = getClassifications();
        // Build a navigation bar using the $classifications array
        $navList = '<ul>';
        $navList .= "<li><a href='/index.php' title='View the PHP Motors home page'>Home</a></li>";
        foreach ($classifications as $classification) {
          $navList .= "<li> <a href='/vehicles/?action=classification&classificationName="
            .urlencode($classification['classificationName']).
            "' title='View our $classification[classificationName] lineup of vehicles'>$classification[classificationName]</a> </li>";
         }
        $navList .= '</ul>';
        include '../view/add-classification.php';
        exit;
      } else {
        $message = "<p>Sorry $classificationName, but the registration failed. Please try again.</p>";
        include '../view/add-classification.php';
        exit;
      }

      
      break;
     case 'adding-vehicle':
         // Filter and store the data
        $invMake = filter_input(INPUT_POST, 'invMake', FILTER_SANITIZE_STRING);
        $invModel = filter_input(INPUT_POST, 'invModel', FILTER_SANITIZE_STRING);
        $invDescription = filter_input(INPUT_POST, 'invDescription', FILTER_SANITIZE_STRING);
        $invImage = filter_input(INPUT_POST, 'invImage', FILTER_SANITIZE_STRING);
        $invThumbnail = filter_input(INPUT_POST, 'invThumbnail', FILTER_SANITIZE_STRING);
        $invPrice = filter_input(INPUT_POST, 'invPrice', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
        $invStock = filter_input(INPUT_POST, 'invStock', FILTER_SANITIZE_NUMBER_INT);
        $invColor = filter_input(INPUT_POST, 'invColor', FILTER_SANITIZE_STRING);
        $classificationId = filter_input(INPUT_POST, 'classificationId', FILTER_SANITIZE_NUMBER_INT);
        // Check for missing data
        if(empty($invMake)|| empty($invModel)||empty($invDescription)||empty($invImage)||empty($invThumbnail)||empty($invPrice)||empty($invStock)||empty($invColor)||empty($classificationId) ){
          $message = '<p>Please provide information for all empty form fields.</p>';
          include '../view/add-vehicle.php';
          exit;
        }
        
        // Send the data to the model
        $regOutcome = regVehicle($invMake, $invModel, $invDescription, $invImage, $invThumbnail, $invPrice, $invStock, $invColor, $classificationId);
        
        // Check and report the result
        if($regOutcome === 1){
          $message = "<p>Thanks for registering $invModel.</p>";
          include '../view/add-vehicle.php';
          exit;
        } else {
          $message = "<p>Sorry $classificationName, but the registration failed. Please try again.</p>";
          include '../view/add-vehicle.php';
          exit;
        }
        break;
    case 'vehicle':
      if (isset($_SESSION['message'])) {
        $message = $_SESSION['message'];
       }
      if (isset($_SESSION['loggedin'])  && $_SESSION['clientData']['clientLevel']>1){
        $classificationList = buildClassificationList($classifications);
        include '../view/vehicle-man.php';
      } else {
       header('Location: /index.php');
      }
      break;
    
    case 'mod':
      $invId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
      $invInfo = getInvItemInfo($invId);
      if(count($invInfo)<1){
        $message = 'Sorry, no vehicle information could be found.';
      }
      include '../view/vehicle-update.php';
      exit;
      break;

    /* * ********************************** 
    * Get vehicles by classificationId 
    * Used for starting Update & Delete process 
    * ********************************** */ 
    case 'getInventoryItems': 
      // Get the classificationId 
      $classificationId = filter_input(INPUT_GET, 'classificationId', FILTER_SANITIZE_NUMBER_INT); 
      // Fetch the vehicles by classificationId from the DB 
      $inventoryArray = getInventoryByClassification($classificationId); 
      // Convert the array to a JSON object and send it back 
      echo json_encode($inventoryArray); 
      break;
    
    case 'updateVehicle':
      $classificationId = filter_input(INPUT_POST, 'classificationId', FILTER_SANITIZE_NUMBER_INT);
      $invMake = filter_input(INPUT_POST, 'invMake', FILTER_`enter code here`SANITIZE_STRING);
      $invModel = filter_input(INPUT_POST, 'invModel', FILTER_SANITIZE_STRING);
      $invDescription = filter_input(INPUT_POST, 'invDescription', FILTER_SANITIZE_STRING);
      $invImage = filter_input(INPUT_POST, 'invImage', FILTER_SANITIZE_STRING);
      $invThumbnail = filter_input(INPUT_POST, 'invThumbnail', FILTER_SANITIZE_STRING);
      $invPrice = filter_input(INPUT_POST, 'invPrice', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
      $invStock = filter_input(INPUT_POST, 'invStock', FILTER_SANITIZE_NUMBER_INT);
      $invColor = filter_input(INPUT_POST, 'invColor', FILTER_SANITIZE_STRING);
      $invId = filter_input(INPUT_POST, 'invId', FILTER_SANITIZE_NUMBER_INT);
      
      if (empty($classificationId) || empty($invMake) || empty($invModel) || empty($invDescription) || empty($invImage) || empty($invThumbnail) || empty($invPrice) || empty($invStock) || empty($invColor)) {
      $message = '<p>Please complete all information for the updated item! Double check the classification of the item.</p>';
      include '../view/vehicle-update.php';
      exit;
      }
      $updateResult = updateVehicle($invMake, $invModel, $invDescription, $invImage, $invThumbnail, $invPrice, $invStock, $invColor, $classificationId, $invId);
      if ($updateResult) {
        $message = "<p class='notify'>Congratulations, the $invMake $invModel was successfully updated.</p>";
        $_SESSION['message'] = $message;
        header('location: /vehicles/index.php?action=vehicle');
        exit;
       } else {
        $message = "<p>Error. The vehicle was not updated.</p>";
        include '../view/vehicle-update.php';
        exit;
      }
      break;
  case 'del':
    $invId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
    $invInfo = getInvItemInfo($invId);
    if (count($invInfo) < 1) {
        $message = 'Sorry, no vehicle information could be found.';
      }
      include '../view/vehicle-delete.php';
      exit;
      break;
  case 'deleteVehicle':
    $invMake = filter_input(INPUT_POST, 'invMake', FILTER_SANITIZE_STRING);
    $invModel = filter_input(INPUT_POST, 'invModel', FILTER_SANITIZE_STRING);
    $invId = filter_input(INPUT_POST, 'invId', FILTER_SANITIZE_NUMBER_INT);
    
    $deleteResult = 'deleteVehicle'($invId);
    if ($deleteResult) {
      $message = "<p class='notice'>Congratulations the, $invMake $invModel was   successfully deleted.</p>";
      $_SESSION['message'] = $message;
      header('location: /vehicles/index.php?action=vehicle');
      exit;
    } else {
      $message = "<p class='notice'>Error: $invMake $invModel was not
    deleted.</p>";
      $_SESSION['message'] = $message;
      header('location: /vehicles/index.php?action=vehicle');
      exit;
    }
    break;
    case 'classification':
      $classificationName = filter_input(INPUT_GET, 'classificationName', FILTER_SANITIZE_STRING);
      $vehicles = getVehiclesByClassification($classificationName);
      if(!count($vehicles)){
       $message = "<p class='notice'>Sorry, no $classificationName could be found.</p>";
      } else {
       $vehicleDisplay = buildVehiclesDisplay($vehicles);
      }
      include '../view/classification.php';
      break;
    case 'vehicleDetails':
      $invId = filter_input(INPUT_GET, 'invid', FILTER_VALIDATE_INT);
      $vehicleData = getInvItemInfo($invId);
      $_SESSION['vehicleData'] = $vehicleData;
      include '../view/vehicle-detail.php';
      break;
    default:
      $classificationList = buildClassificationList($classifications);
      include '../view/vehicle-man.php';
      break;
   
}

Take a look at your function getInvItemInfo .看看你的 function getInvItemInfo What does that function return if no records can be found?如果找不到记录,那 function 返回什么? If it returns NULL you will receive an error since you are trying to count(NULL) .如果它返回 NULL 您将收到一个错误,因为您正在尝试count(NULL)

Try to use the function is_null() instead of count() .尝试使用 function is_null()而不是count()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我收到一个错误“警告:mysql_fetch_array() 期望参数 1 是资源,布尔值在 C:\\xampp\\htdocs\\....” - I am getting an error "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\...." 我发送附件邮件时出错警告:filesize() - Getting error when i am sending attachment mail Warning: filesize() 为什么在此PHP foreach循环中收到警告错误? - Why am I getting a Warning error in this PHP foreach loop? 我收到此错误,尽管它可以正常工作,但会发出警告 - i am getting this error although its working but its gives warning 为什么我在尝试计算 mysqli 结果时会收到警告? - Why am I getting a warning when I try to count a mysqli result? 尝试更新到 PHP 7.4 但在元素中出现此错误,警告:count(): Parameter must be an array or an object that implements Countable - Trying to update to PHP 7.4 but getting this error in an element, Warning: count(): Parameter must be an array or an object that implements Countable 为什么我在我的网站顶部收到“警告:array_filter() 期望参数 1 是数组,给定布尔值”? - Why am I getting "Warning: array_filter() expects parameter 1 to be array, bool given" at the top of my website? 为什么我收到一条错误,指出“mail()期望参数1是字符串”? - Why am I getting an error stating that “mail() expects parameter 1 to be string”? PHP MYSQL:为什么我收到此警告? - PHP MYSQL : why i am getting this warning? 为什么在使用具有常量值的 bindParam 时出现无法通过引用传递参数 2 错误? - Why I am getting Cannot pass parameter 2 by reference error when I am using bindParam with a constant value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM