数据修改期间的问题

时间:2010-06-06 13:01:08

标签: php mysql

这里是我的代码 -

if($pin == '105') {
 $sqltree = "INSERT INTO tbltree (`userId`, `level`, `superId`, `rootId`, `childcount`) 
                            VALUES ('$child1', '1', '$newid', '$myroot', '0');";
    mysql_query($sqltree);
    update_level($newid);
}
function update_level()
    {
        //for 1st level
            $newid = $_SESSION['newid'];
            //getting senior's level 1 and to increase by 1
            $sqlgetlevel = "SELECT superId,level1 FROM tbltree WHERE userID='$newid'";
            echo "<br>test:".$sqlgetlevel;
            $result = mysql_query($sqlgetlevel,$link)or die(mysql_error());  //line 340
            $row = mysql_fetch_array($result, MYSQL_ASSOC);
            $level1 = $row["level1"];
            $level1 = $level1 + 1;

            //update increased level
            $sqlupdate = "UPDATE tbltree SET level1='$level1' WHERE userId='$newid';";
            mysql_query($sqlupdate,$link)or die(mysql_error()); 

            //change superId for new level
            $superid = $row["superId"];
}

错误 - test:SELECT superId,level1 FROM tbltree WHERE userID='29277640'
Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\303\levelupdate.php on line 340

1 个答案:

答案 0 :(得分:0)

$ link在你的函数中是未知的,使它成为全局变量或者只是不使用它。

  
    

$ result = mysql_query($ sqlgetlevel)或die(mysql_error()); //第340行