Ibshas25 Posted November 16, 2010 Share Posted November 16, 2010 i am getting this error below and i know its something small but cant see it.. help <b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/export/SOI-50/students/m2009/abhr428/web/WebIbs/projectSearchPBT1.php</b> on line <b>30</b><br /> <?php include("JSON.php"); require_once("connectdb.php"); $req = json_decode(stripslashes($_POST['data']), true); $req["SuccFail"]="fail"; $req["SuccFailMessage"]="Error Occured."; $req["ResultData"]=""; //$logFile = 'logFile'; // error_log("isl=baþladý: ", 3, $logFile); if ($req['operation'] == "projectsearch") // select için veri geldi { // error_log("isl==select oluþuyor: ", 3, $logFile); $sql= "select prj_id,prj_projectname,prj_metodid,prj_startdate, prj__enddate ,prj_iscompleted from projects "; // $sql.=" where (rol_id is null or rol_id = ". $req['rol'][0]['rolid']." ) and "; $sql.= "where (prj_projectname is null or prj_projectname like '". $req['prj'][0]['name']."%' ) "; $sql .= " order by prj_id"; // error_log($sql, 3, $logFile); $result = mysql_query($sql); //select rol_Id,rol_name,rol_projectMng,rol_teamsMng, rol_rolesMng ,rol_usersMng,rol_metodMng,rol_ranklevel,rol_recorddate,rol_recordId from roles where (rol_name is null or rol_name like '%' ) order by rol_name $reslist = "<table border='1'><tr><th>Project Id</th><th>Name</th><th>Project methof</th><th>Start Date</th><th> End date</th><th>Is project completed</th></tr>"; while($row = mysql_fetch_array($result)) { // rolid,name ,projectMng,teamsMng,rolesMng,usersMng,metodsMng,ranklevel // error_log("user: ".$row['usr_name']." surname :".$row['usr_username'], 3, $logFile); $reslist .= "<tr><td><a href='#' onclick='javascript:ProjectSearchChoose(".$row['prj_id'].", ".chr(34).$row['prj_projectname'].chr(34).",".chr(34).$row['prj_metodid'].chr(34).", ".chr(34).$row['prj_startdate'].chr(34).",".chr(34).$row['prj_enddate'].chr(34).",".chr(34).$row['prj_iscompleted'].");' >".$row['prj_id']."</a></td><td>".$row['prj_projectname']."</td><td>".$row['prj_metodid']."</td><td> ".$row['prj_startdate']."</td><td>".$row['prj_enddate']."</td><td>".$row['prj_iscompleted']."</td></tr>"; } // error_log($reslist, 3, $logFile); // error_log("$reslist: ".$reslist, 3, $logFile); $reslist .= "</table>"; $req["SuccFail"]="success"; //operation success or fail $req["SuccFailMessage"]="successfully selected."; //alert($reslist); $req["ResultData"]=$reslist; mysql_close($conn); header("Content-type: text/plain"); echo json_encode($req); return; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/218853-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-res/ Share on other sites More sharing options...
mikosiko Posted November 16, 2010 Share Posted November 16, 2010 because more likely your query is incorrect and not producing the results that you expect. suggestions: - Add the 2 lines in my signature at the beginning of your code after your "<?php" tag... it will help you to deal with errors more easily. - Change at least this line $result = mysql_query($sql); to this: $result = mysql_query($sql) or die("Query : " . $sql . " Error : " . mysql_error()); this will allow you to see the real final query that you are sending to the DB and also to display any error if the sentence is incorrect.. stopping the code if something goes wrong. Quote Link to comment https://forums.phpfreaks.com/topic/218853-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-res/#findComment-1135008 Share on other sites More sharing options...
ManiacDan Posted November 16, 2010 Share Posted November 16, 2010 Also, there is only one instance of mysql_fetch_array in that code. It has one argument. The error message is "the argument to mysql-fetch-array is wrong." From that, you can deduce that $result is wrong. Move up from there to find where it's set. That's wrong. Etc etc. Debugging is tedious, not magical. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218853-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-res/#findComment-1135009 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.