xxreenaxx1 Posted March 9, 2011 Share Posted March 9, 2011 I have tired to search this up but get nothing back.. :@ This error is on line 18 on line 18 is if (mysql_num_rows($result) == 1) { Notice: Undefined variable: result in C:\xampp\htdocs\Exam_Online\Staff_login\Staff_login_process.php on line 18 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Exam_Online\Staff_login\Staff_login_process.php on line 18 Wrong Username or Password This is the error message. if (mysql_num_rows($result) == 1) { // Set username session variable $_SESSION['ID'] = $_POST['ID']; header("location:Staff_Menu.php"); } else { echo"Wrong Username or Password"; } Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
litebearer Posted March 9, 2011 Share Posted March 9, 2011 Please show the query and the execution of the query Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1185002 Share on other sites More sharing options...
PFMaBiSmAd Posted March 9, 2011 Share Posted March 9, 2011 The error message is self explanatory, the parameter you supplied, $result, to the function is a null. You would need to determine why $result is a null in your code. Best guess, since you didn't post the relevant code prior to the error, is that you don't have a $result variable in your code. Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1185004 Share on other sites More sharing options...
xxreenaxx1 Posted March 9, 2011 Author Share Posted March 9, 2011 SELECT * FROM user WHERE (Use_ID = '1') and (Use_Password = '12567')and (Rol_ID = '2') This is my query. And the query actually works. <?php function fnclogin(){ $con = fncOpenConnection(); mysql_select_db("Examination", $con); $result = mysql_query("SELECT * FROM user WHERE (Use_ID = '" . mysql_real_escape_string($_POST['ID']) . "') and (Use_Password = '" . mysql_real_escape_string($_POST['password']) . "')and (Rol_ID = '1')") or die('Cannot Execute:'. mysql_error()); fncCloseConnection($con); return $result; } ?> This is my code and including this in to my php as include '../Database/login.php'; Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1185052 Share on other sites More sharing options...
kenrbnsn Posted March 9, 2011 Share Posted March 9, 2011 How are you calling this function? Ken Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1185054 Share on other sites More sharing options...
xxreenaxx1 Posted March 9, 2011 Author Share Posted March 9, 2011 Oops.. I am new to function. Have No idea how to use it or even what that is. Any website you would like to recommend me to. I was focused to use this function thing Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1185057 Share on other sites More sharing options...
kenrbnsn Posted March 9, 2011 Share Posted March 9, 2011 Please post all of the code. Ken Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1185075 Share on other sites More sharing options...
xxreenaxx1 Posted March 9, 2011 Author Share Posted March 9, 2011 $query=fncsubject(); $result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() ); echo "<select name=myselect>"; while($row=mysql_fetch_array($result)){ echo "<OPTION VALUE=".$row['Sub_ID'].">".$row['Sub_Name']."</OPTION>"; } echo "</select>"; This is my code for a form and would like to call this function <?PHP function fncsubject(){ $con = fncOpenConnection(); mysql_select_db("Examination", $con); $result = mysql_query("SELECT DISTINCT s.Sub_ID, s.Sub_Name FROM user u, user_x_subject us, subject s, test t WHERE u.Use_ID = '{$_SESSION['username1']}' AND u.Use_ID = us.Use_ID AND s.Sub_ID = us.Sub_ID AND us.Sub_ID = t.Sub_ID") or die('Cannot Execute:'. mysql_error()); fncCloseConnection($con); return $result; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1185077 Share on other sites More sharing options...
litebearer Posted March 9, 2011 Share Posted March 9, 2011 No offense; however, it appears you need to do a little research on functions, variables and mysql. Here is a start - http://www.devshed.com/c/a/PHP/PHP-Functions/ The reason(s)? A) You are trying to use variables in your functions that are local in scope - they exist outside the function, but have either need to be passed as parameters or declared global; B), you are trying to use a result as a query. There is no shame in not knowing something; BUT, if you are going to use something, it is CRITICAL to learn when, where, why and how it works. That way you can avoid problems and/or fix them when they do occur. (We all have code that doesn't work the first 20 or 30 times we try it - at least I do - I wear more ink off my keyboard fixing my mistakes than I do writing code) Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1185163 Share on other sites More sharing options...
xxreenaxx1 Posted March 10, 2011 Author Share Posted March 10, 2011 I appreciate your help and I did mention about me not knowing function. But thanks for the tips. I am reading the link you have provided me, Hopefully that should cover everything I want to know about function. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/230095-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1185514 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.