gelobelmonte Posted September 3, 2012 Share Posted September 3, 2012 Good day phpfreaks people! i'm a newbie in web programming and I encountered this problem.. I don't know how to fix it.. please help me.. this error prompts everytime i try logging in.. The registration for works but the login doesn't.. please help me.. this is my code where the error is.. $db = mysql_connect($mysql_server, $mysql_username, $mysql_password); mysql_select_db($mysql_database, $db); $sql = "SELECT password, fullname, active FROM ".$mysql_table." WHERE username = '".$_POST['username']."'"; $result = mysql_query($sql, $db); if ($data = mysql_fetch_array($result)) { if ($crypt_pass == $data['password'] && $data['active'] != 0) { $found = true; $fullname = $data['fullname']; } } mysql_close($db); if($found == false) { header('Location: '.$error_page); exit; } else { session_start(); $_SESSION['username'] = $_POST['username']; $_SESSION['fullname'] = $fullname; $rememberme = isset($_POST['rememberme']) ? true : false; if ($rememberme) { setcookie('username', $_POST['username'], time() + 3600*24*30); setcookie('password', $_POST['password'], time() + 3600*24*30); } header('Location: '.$success_page); exit; } } Thanks in advance for your help.. Gelo Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/ Share on other sites More sharing options...
Pikachu2000 Posted September 3, 2012 Share Posted September 3, 2012 Your query execution is failing and returning a boolean FALSE. Echo mysql_error, along with the query string to see what the error is and what might have caused it. Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1374775 Share on other sites More sharing options...
gelobelmonte Posted September 3, 2012 Author Share Posted September 3, 2012 Thanks for your fast response sir.. But what is supposed to be my right code? I'm just a newbie on this that's why I don't have any idea.. Thank you sir! Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1374971 Share on other sites More sharing options...
trq Posted September 4, 2012 Share Posted September 4, 2012 You need to read Pikachu2000's reply again. It's better you learn how to find and fix errors rather than have someone simply do it for you. Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1374975 Share on other sites More sharing options...
gelobelmonte Posted September 4, 2012 Author Share Posted September 4, 2012 can you explain it to me simpler then? I really don't understand that much.. Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375034 Share on other sites More sharing options...
Pikachu2000 Posted September 4, 2012 Share Posted September 4, 2012 Did you read the PHP manual entry for mysql_error() I linked to in my previous post? Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375041 Share on other sites More sharing options...
gelobelmonte Posted September 5, 2012 Author Share Posted September 5, 2012 Yes, I have read it.. But I really don't know how to use it. Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375321 Share on other sites More sharing options...
Pikachu2000 Posted September 5, 2012 Share Posted September 5, 2012 The examples are quite clear, which part has you stuck? Post the code you tried to use it in and the errors/problems you encountered. Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375325 Share on other sites More sharing options...
gelobelmonte Posted September 6, 2012 Author Share Posted September 6, 2012 The examples are quite clear, which part has you stuck? Post the code you tried to use it in and the errors/problems you encountered. I am not sure on how to use it.. but i tried it this way.. this is where the error occurs $db = mysql_connect($mysql_server, $mysql_username, $mysql_password); mysql_select_db($mysql_database, $db); $sql = "SELECT password, fullname, active FROM ".$mysql_table." WHERE username = '".$_POST['username']."'"; $result = mysql_query($sql, $db); if ($data = mysql_fetch_array($result)) { if ($crypt_pass == $data['password'] && $data['active'] != 0) { $found = true; $fullname = $data['fullname']; } else die(mysql_error()); } mysql_close($db); if($found == false) { header('Location: '.$error_page); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375634 Share on other sites More sharing options...
gelobelmonte Posted September 6, 2012 Author Share Posted September 6, 2012 Additional info: i tried adding this: $result = mysql_query($sql, $db) or trigger_error ( mysql_error ( ) ); but a notice prompted at the error message as follows: Unknown column 'active' in 'field list' in /home/mcssonli/public_html/login.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375640 Share on other sites More sharing options...
Pikachu2000 Posted September 6, 2012 Share Posted September 6, 2012 Well then, there you have it. There is apparently no field named `active` in your table. Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375644 Share on other sites More sharing options...
gelobelmonte Posted September 6, 2012 Author Share Posted September 6, 2012 Well then, there you have it. There is apparently no field named `active` in your table. Wow, I think I'm a bit closer.. I need to make a field on the table named as 'active' then? What would be the suggested parameters? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375650 Share on other sites More sharing options...
Pikachu2000 Posted September 6, 2012 Share Posted September 6, 2012 I haven't the slightest idea. I don't know what the rest of the application does. Where did this code come from? Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375653 Share on other sites More sharing options...
gelobelmonte Posted September 6, 2012 Author Share Posted September 6, 2012 this is from the login form of our website. www.mcssonline.org. the registration seem to work fine.. Quote Link to comment https://forums.phpfreaks.com/topic/267933-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean/#findComment-1375666 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.