使用MySQL,PHP的未定义索引

时间:2016-04-11 00:32:43

标签: php mysql ajax xampp

我搜索了类似的问题,但我无法找到解决问题的方法。我如何在PHP中调试MySQL问题?找到这些错误的原因总是非常耗时。在JavaScript中查找/修复错误要容易得多。

错误:

  

注意:未定义的索引:第48行的C:\ xampp \ htdocs \ Noobs_Search \ serverCode \ findPlayers.php中的角色

     

注意:未定义的索引:第49行的C:\ xampp \ htdocs \ Noobs_Search \ serverCode \ findPlayers.php中的性别

这是指这些界限:

Template.topNavbar.helpers({
  activeIfTemplateIs: function (template) {
    var currentRoute = FlowRouter.getRouteName();
    return currentRoute && template === currentRoute ? 'active' : '';
  }
});

PHP代码:

$role   = $row['role'];
$g      = $row['gender'];

JavaScript的:

<?php

require "connect.php";

$searchBy   = $_GET["field"]; 
$searchText = $_GET["text"];

$playerSQL  =   "SELECT * 
                 FROM vw_playerTeamName";

if( isset($GET_["role"]) )
{
    $role       = $_GET["role"];
    $playerSQL .= " AND role = $role";//  .= is same as +=
}

if( isset($GET_["gender"]) )
{
    $gender     = $_GET["gender"];
    $playerSQL .= " AND gender = $gender";//  .= is same as +=
}

$result = $mysqli->query($playerSQL);

$pTable =   "<div class='table'>
        <div class='heading'>
            <div class='cell'>ID</div>
            <div class='cell'>First</div>
            <div class='cell'>Last</div>
            <div class='cell'>Email</div>
            <div class='cell'>Team</div>
            <div class='cell'>Gender</div>
            <div class='cell'>Role</div>
        </div>";

while($row = $result->fetch_array())
{
    $ID     = $row['ID'];
    $first  = $row['first'];
    $last   = $row['last'];
    $email  = $row['email'];
    $team   = $row['team_name'];
    $role   = $row['role'];
    $g      = $row['gender'];

    $pTable .=  "<div class='row'>
                    <div class='cell'>$ID</div>
                    <div class='cell'>$first</div>
                    <div class='cell'>$last</div>
                    <div class='cell'>$email</div>
                    <div class='cell'>$team</div>
                    <div class='cell'>$g</div>
                    <div class='cell'>$role</div>
                </div>";
}

$pTable .= "</div>";

$mysqli->close();

echo $pTable;
?>

HTML代码:

$(document).ready(function()
{

    $('#search').click(function()
    {
        var searchField = $("#searchType").val();
        var searchText  = $("#searchText").val();
        var g           = $("input[name=gender]:checked").val();
        var r           = $("input[name=role]:checked").val();

        $.get("serverCode/findPlayers.php",
        {
            field:searchField,
            text:searchText,
            role:r,
            gender:g
        },function(response)
        {
            $("#placeholder").html(response);
        });

    });

});

1 个答案:

答案 0 :(得分:0)

看起来你把它拼错了是$ _GET

 if( isset($_GET["role"]) )
{
    $role       = $_GET["role"];
    $playerSQL .= " AND role = $role";//  .= is same as +=
}

if( isset($_GET["gender"]) )
{
    $gender     = $_GET["gender"];
    $playerSQL .= " AND gender = $gender";//  .= is same as +=
}