Web Host上的未知错误,但代码在localhost上运行良好

时间:2013-12-12 17:25:34

标签: php jquery mysql ajax

我刚刚完成了一个在我的localhost中运行的表单,它运行得很好,但是当我将代码上传到Web主机时,它没有按预期工作。它是一个使用PHP,MySQL和JQuery的简单表单。当我点击提交时,它显示我的自定义错误窗口,说明电子邮件已经注册,但问题是数据库是空的。我在ajax部分中放了一些代码来检查电子邮件,这就是它所说的内容(它应该只显示一个数字):


警告:mysql_fetch_assoc():提供的参数不是 /*/*/public_html/check_user.php中的有效MySQL结果资源 17

这是check_user.php:

<?php
require_once("SqlChromoConnection.php");

// Check if email is not empty in the form
if(isset($_POST['email'])) {

    // create the query
    $sql = "SELECT COUNT(*) AS count
            FROM Users
            WHERE email = '" . trim($_POST['email']) . "'";

    // create object to handle the connection
    $conn = new SqlChromoConnection();
    $conn->getDatabaseConnection();     // establish a connection

    $data = $conn->executeQuery($sql);  // execute query
    $count= mysql_fetch_assoc($data);   // save result in $count
    $exists = $count['count'];      // access only the field 'count'

    $conn->closeConnection();       // close the connection

    echo $exists;

    exit(0);
}

?>

这是检查电子邮件的ajax部分:

if( !re.test(email) || email.indexOf(' ') > 0) {
            message = "Email NOT valid!!!";
            messageDialog("Warning", message, "warning", 2);
            return false;
        } else {
            // use ajax to check if a user has been previously registered
            // using this email
            var valid = false;

            $.ajax(
            {
                url:"check_user.php",   // url that will use
                async: false,
                data:{                  // data that will be sent
                    email:email
                },
                type:"POST",            // type of submision
                dataType:"text",        // what type of data we'll get back
                success:function(data)
                { 
                    window.alert(data);
                    // if check_user returns 0
                    // means that there's no any user registered with that email
                    if(data == 0 ) {
                        valid = true;
                    }
                }
            });

            if(!valid) {
                message = "This email is registered already!";
                messageDialog("Error", message, "error", 2);
                return false;
            }else return true;

        }

正如我所说,代码在localhost中运行良好。

任何建议都会非常感激。

问候。

2 个答案:

答案 0 :(得分:0)

我认为你应该使用用户而不是用户来表名

答案 1 :(得分:0)

mysql_fetch_assoc 之前添加 @ ,它会删除此声明中的所有警告。 使用 @mysql_fetch_assoc()。