[請益] php程式碼問題

看板PHP作者 (roger70349)時間19年前 (2007/01/29 15:12), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/2 (看更多)
請各位大大能否幫我看一下下面的兩隻程式的程式碼那裡有問題 分別為login_chk.php及admin_chk.php 公用程式 my_msg.php <? Function my_header($redirect){ echo "<script language=\"javascript\">"; echo "location.href='".$redirect."'"; echo "</script>"; return; } Function my_msg($msg,$redirect){ echo "<SCRIPT Language=javascript>"; echo "window.alert('".$msg."')"; echo "</SCRIPT>"; echo "<script language=\"javascript\">"; echo "location.href='".$redirect."'"; echo "</script>"; return; } ?> 另一隻共用程式 sql_connect.php <? /* Connecting, selecting database */ $link = mysql_connect('localhost', 'root', 'roger') or die("Could not connect : " . mysql_error()); //echo "Connected successfully"; mysql_select_db("danshui") or die("Could not select database"); mysql_query("SET NAMES 'big5'"); //顯示中國偉大的文學 ?> 兩隻程式 login_chk.php <? include_once("sql_connect.php"); include_once("my_msg.php"); ?> <? //檢核資料 if($_POST['id']=='' or $_POST['password']==''){ my_msg("欄位不可空白","login.html"); } $sqlstr="select * from member where id ='".$_POST['id']."' and password = '".$_POST['password']."' and status = 1"; $result = mysql_query($sqlstr,$link); $row = mysql_fetch_array($result, MYSQL_BOTH); if(mysql_num_rows ($result)==1 && $row["rank"]==100){ setcookie("cookie_chk", "adm_logined"); setcookie("cookie_id", $_POST['id']); my_header("adm.php");// 管理者登入 }elseif(mysql_num_rows ($result)==1 && $row["rank"]==1){ setcookie("cookie_chk", "logined"); setcookie("cookie_id", $_POST['id']); my_header("main.php");// 會員登入 }else{ my_msg("登入失敗,請重新登入","login.html"); } mysql_free_result($result); mysql_close($link); ?> 還有另一隻程式是 admin_chk.php <? $link = mysql_connect("localhost","root","roger"); mysql_query("danshui"); $sqlstr="select * from user where id ='".$_POST['id']."' and passwd = '".$_POST['passwd']."'"; $result = mysql_query($sqlstr,$link); if(mysql_num_rows ($result)){ echo "<center>管理者登入成功</center>"; }else{ echo "<center>管理者登入失敗</center>"; } ?> 但在執行後出現 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\AppServ\www\danshui\member\admin_chk.php on line 17 請問各位大大,以上兩隻程式的問題出在那裡,謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.21.79.80

01/29 15:36, , 1F
admin_chk.php 第十七行
01/29 15:36, 1F

01/29 17:50, , 2F
你的Querry沒東西所以出錯
01/29 17:50, 2F
文章代碼(AID): #15lPvWEI (PHP)
文章代碼(AID): #15lPvWEI (PHP)