if($_GET['confirm']){
        $coupon_id = $_GET['confirm'];
        $query = mysql_query("SELECT * FROM purchases WHERE coupon_id = '$coupon_id'");
            while($rows = mysql_fetch_array($query)){
                $user_id = $rows['user_id'];
                $query = mysql_query("INSERT INTO purchases_confirm VALUES(NULL,'$coupon_id','$user_id' ");
                if($query){
                    echo "inserting new values to database....done !";
                }
            }
        exit;
        }

它输出:Warning:mysql_fetch_array():提供的参数不是一个有效的mysql结果资源…奇怪的是,如果我从命令行或phpmyadmin执行查询,它就会工作!!

最佳答案

当使用$query时,不能在内部重新分配mysql_fetch_array变量。
应该是:

   if($_GET['confirm']){
        $coupon_id = $_GET['confirm'];
        $query = mysql_query("SELECT * FROM purchases WHERE coupon_id = '$coupon_id'");
            while($rows = mysql_fetch_array($query)){
                $user_id = $rows['user_id'];
                $query2 = mysql_query("INSERT INTO purchases_confirm VALUES(NULL,'$coupon_id','$user_id' ");
                if($query2){
                    echo "inserting new values to database....done !";
                }
            }
        exit;
        }

关于php - 奇怪的mysql_fetch_array错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5329865/

10-11 09:16