dsxon40042 2010-03-09 01:44
浏览 28
已采纳

为什么我得到“mysql_query():提供的参数不是有效的”

Why do I get a "mysql_query(): supplied argument is not a valid" for the first...

$r = mysql_query($q, $connection);

In the following code...

$bId    = trim($_POST['bId']);
$title  = trim($_POST['title']);
$story  = trim($_POST['story']);

$q  = "SELECT * ";
$q .= "FROM " . DB_NAME . ".`blog` ";
$q .= "WHERE `blog`.`id` = {$bId}";
$r = mysql_query($q, $connection);
//confirm_query($r);
if (mysql_num_rows($r) == 1) {      
    $q  = "UPDATE " . DB_NAME . ".`blog` SET
                        `title` = '{$title}',
                        `story` = '{$story}'
                    WHERE `id` = {$bId}";
    $r = mysql_query($q, $connection);
    if (mysql_affected_rows() == 1) {
        //Successful
        $data['success'] = true;
        $date['errors']  = false;
        $date['message'] = "You are the Greatest!";
    } else {
        //Fail
        $data['success'] = false;
        $data['error']   = true;
        $date['message'] = "You can't do it fool!";
    }        
}

I also get an "mysql_num_rows(): supplied argument is not a valid MySQL result resource" error too.

Side notes: I am using 1&1 Hosting (worst hosting ever), custom .htaccess file with one line text to enable PHP 5.2 (only way with 1&1 Hosting).


Extra stuff add after the questions was posted...

Here is how $connection is defined. It is on its own page called connection.php that is called up using the require_once function. It it is called up on every page that require a database connection including the one in question...

$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
    if (!$connection) {
        die("Database Connection Failed: </br>" . mysql_error());
    }
    $db_select = mysql_select_db(DB_NAME,$connection);
    if (!$db_select) {
        die("Database Selection Failed: </br>" . mysql_error());
    }

... I know it is working because this the same connect that I use for the page I have and I have no problems with it. I havent testing on my home server yet, but I am going to later to see if it is related to a 1&1 Hosting issue.

UPDATE: I am in the process of moving from 1&1 Hosting to HostMoster. 1&1 runs a PHP as CGI and runs PHP4 instead of PHP5 (you can make a custom .htaccess file to make it run PHP5). I will update you later.

  • 写回答

4条回答 默认 最新

  • duancashi1362 2010-03-09 01:47
    关注

    The first would be because it's not a connection, and the second would be because it's not a query result because it wasn't a connection. Use mysql_error() to figure out what went wrong in the connection.

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

报告相同问题?

悬赏问题

  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题