dongmeiba6151 2013-09-02 18:08
浏览 29
已采纳

警告:mysql_num_rows()期望参数1是资源,布尔[重复]

Here's the php

<?php
if (
isset($_POST['tour_name'])&&
isset($_POST['pot'])&&
isset($_POST['max_players'])&&
isset($_POST['min_players'])){

    $tour_name = $_POST['tour_name'];
    $pot = $_POST['pot'];
    $max_players = $_POST['max_players'];
    $min_players = $_POST['min_players'];

    if (!empty($tour_name)&&!empty($pot)&&!empty($max_players)&&!empty($min_players)) {
        if (($min_players >= 2) && ($min_players <= 6)) {
            if (($max_players >= 2) && ($min_players <= 12)) {
                if (($pot >= 1) && ($pot <= 100)) {

                    $query = "SELECT `tour_name` FROM `tournies` WHERE `tour_name`='$tour_name'";
                    $query_run = mysql_query($query);

                    if (mysql_num_rows($query_run)==1) {
                    echo 'There is already a tournament with the name '.$tour_name.'.';
                    } else {
                        $query = "INSERT INTO `tournies` VALUES ('', '".mysql_real_escape_string($tour_name)."', '".mysql_real_escape_string($pot)."', '".mysql_real_escape_string($max_players)."', '".mysql_real_escape_string($min_players)."')";
                        if ($query_run = mysql_query($query)) {
                            header('Location: table.php');
                        } else {
                            echo 'Registration was not a win.';
                        }
                    }

                } else {
                    echo 'The pot must be 1-100';
                }
            } else {
                echo 'Maximum players must be atleast 2 and no more then 12';
            }
        } else {
            echo 'Minimum players must be atleast 2, and no more then 6';
        }
    } else {
        echo 'All fields are required';
    }
}

?>

The error is Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Users\Jared\Desktop\xampp\htdocs\tournaments\NewTournament.inc.php on line 69

</div>
  • 写回答

2条回答 默认 最新

  • douhe2305 2013-09-02 18:27
    关注

    Your query probably failed. Use mysql_error() to determine the error.

    I make it a personal practice to add error checking to any query, just in case something like this happens. It can be as simple as this:

    if(!$query_run){
        echo "Error in query:" . $query . "   MYSQL Error:" . mysql_error();
    }
    

    As a side note, mysql function in php has been depreciated. You might want to consider using Mysqli or PDO instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化