查询无法在实时服务器上运行/运行

时间:2017-03-19 21:24:48

标签: php mysql server localhost hosting

首先,你必须相信我:我使用的查询都是正确的(测试方法很多,而且一切都在localhost上完美运行)。让我们开始解释我的问题:我正在运行一个小应用程序(为了好玩和学习),我做了很多关于ajax请求的东西,这有效我可以在开发人员工具中看到它"发送,这些请求转到function.php文件,应该运行。函数文件中的代码看起来有点像这样:

if (isset($_POST['search'])) {
 // Do stuff like running a query
}

所有请求都通过if语句,但在正确写入时,所有以下查询都会失败。所以我尝试在现场服务器上显示错误,但我似乎无法完成它(尝试了ini_set显示错误,使用htacces,并且在服务器设置中乱糟糟的很多),所以我无法看到由于这段代码而导致查询失败的任何错误:

if ($query = mysqli_query($conn, "sql query bla bla")) {
// Dp stuff
} else {
// return error Message
echo "<p style='color:red;'>Something went wrong, please try again!</p>";
}

我总是出错?

方向: 我有一个名为functions的文件夹,里面有多个function.php文件,所有这些都连接到数据库indivitualy,也许这与它有关?

此问题不会仅在一个文件上发生,但所有function.php文件都不起作用。如果我把PHP代码放在原始文件本身一切正常

希望有人可以帮助我,我没有建议

PS我的英语不是很好的希望你会理解!如果没有让我知道或者如果您需要更多信息也请告诉我!

修改

    <?php
include_once'/../includes/dbconfig.php';

// If something is posted
if (isset($_POST['search'])) {
    $word = stripVariables($_POST['search']);

    $querySearch = "SELECT name, description, group_id FROM groups WHERE name LIKE '%$word%'";
    $resultSearch = mysqli_query($conn, $querySearch);
    $numberSearch = mysqli_num_rows($resultSearch);

    // If something is found
    if ($numberSearch >= 1) {
        $end_result = '';

        // Fetch search values, create search results
        foreach ($resultSearch as $row) {
            global $word;

            // Get group values
            $name = $row['name'];
            $description = substr($row['description'], 0, 40);
            $groupId = $row['group_id'];

            // Make typed in word bold
            $bold = '<b>' . $word .'</b>';
            $fullWord = str_ireplace($word, $bold, $name);

            // Create list items for each search result
            $end_result .= "<li class='search-item'><div class='list-text'>" . $fullWord . "<br><b style='font-size:10pt; font-weight:normal'><span id='group_id'>" . $groupId . "</span> ,  " . $description ."...</b></div><div class='list-join'><div id='send_request'><p>Send Request</p></div><div><p>Cancel</p></div></div></li>";

        }

        echo $end_result;

    } else {
        // Nothing found five error
        echo "<li style='color:red; padding: 10px; border: none;'>No results found!</li>";
    }

}

// Prevent injections
function stripVariables($input){
    $var = trim($input);
    $var = strip_tags($var);
    $var = stripslashes($var);
    $var = htmlspecialchars($var);

    return $var;
}
?>

我将此方法与ajax / javascript

一起使用
  $(".join-inner input[name='submit']").click(function(){
        // Get value user input
        var inputSearch = $(".join-inner input[type='text']").val();

        // Setup datastring
        var dataString = "search=" + inputSearch;

        // If inputSearch is not empty
        if (inputSearch) {
            // Ajax call
            $.ajax({
                type: "POST",
                url: "functions/searchGroup.php",
                data: dataString,
                cache: false,
                beforeSend: function(html) {
                    $('.results').html("");
                },
                success: function(html){
                    $('.results').html(html);
                }
            });
        } else {
            $('.results').html("<li style='color:red'>Type something to search</li>")
        }

        return false;
    });

1 个答案:

答案 0 :(得分:0)

你确定$ conn有效吗?

$conn = mysqli_connect("localhost", "my_user", "my_password", "my_db");

/* check connection */
if (mysqli_connect_errno()) {
    echo("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

// Then your code:
if ($query = mysqli_query($conn, "sql query bla bla")) {
    // Dp stuff
} else {
    // return error Message
    echo "<p style='color:red;'>Something went wrong, please try again!</p>";
}