daruga Posted September 29, 2013 Share Posted September 29, 2013 (edited) Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\mkjb\core\functions\users.php on line 4 i need help how to fix this Edited September 29, 2013 by daruga Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/ Share on other sites More sharing options...
daruga Posted September 29, 2013 Author Share Posted September 29, 2013 (edited) <?php function user_exists ($username) { $username = sanitize($username); return(mysql_result(mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'username' = '$username'"), 0) == 1) ? true : false; } function user_active($username){ $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'username' = '$username' AND 'active' = 1"), 0) == 1) ? true : false; } function user_id_from_username($username) { $username = sanitize($username); return mysql_result(mysql_query("SELECT 'user_id' FROM 'users' WHERE 'username' ='$username'"), 0, 'user_id'); } function login ($username, $password) { $user_id = user_id_from_username($username); $username = sanitize($username); $password = md5($password); return (mysql_result(mysql_query("SELECT COUNT ('user_id') From 'users' WHERE 'username' = '$username' AND 'password' = '$password'"), 0) ==1) ? $user_id : false; } ?> Edited September 29, 2013 by daruga Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451646 Share on other sites More sharing options...
Ch0cu3r Posted September 29, 2013 Share Posted September 29, 2013 Remove the quotes around the user_id, users and username fields. MySQL wont treat them as field names but as strings. Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451648 Share on other sites More sharing options...
daruga Posted September 29, 2013 Author Share Posted September 29, 2013 did i need to remove all the quotes around user_id Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451650 Share on other sites More sharing options...
Ch0cu3r Posted September 29, 2013 Share Posted September 29, 2013 (edited) SELECT COUNT ('user_id') From 'users' WHERE 'username' = '$username' AND 'password' = '$password'" All words highlighted in red/purple are field/table names. These should not have quotes wrapped round them. only field values should be wrapped in quotes. Edited September 29, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451653 Share on other sites More sharing options...
daruga Posted September 29, 2013 Author Share Posted September 29, 2013 <aside id="Just_A_Random_ID"> <?php if (logged_in)() === true { echo 'Logged in'; } else { include "includes/widgets/login.php"; } ?> </aside> Parse error: syntax error, unexpected ')' in C:\wamp\www\mkjb\includes\aside.php on line 4 Call Stack # Time Memory Function Location 1 0.0004 140960 {main}( ) ..\register.php:0 2 0.0008 142384 include( 'C:\wamp\www\mkjb\includes\overall\overallheader.php' ) ..\register.php:1 how to fix this error Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451683 Share on other sites More sharing options...
Ch0cu3r Posted September 29, 2013 Share Posted September 29, 2013 (edited) Do you know PHP basic syntax. This is not correct syntax if (logged_in)() === true { Reading the manual on how to properly construct if statements will help http://uk1.php.net/manual/en/control-structures.if.php Edited September 29, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451685 Share on other sites More sharing options...
daruga Posted September 29, 2013 Author Share Posted September 29, 2013 <?php if (logged_in)() === true { echo 'Logged in'; } else { is there a way to do if statement other than my....what we learn in school we been using more familiar with that statement. because i did confuse with java if statement Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451693 Share on other sites More sharing options...
daruga Posted September 29, 2013 Author Share Posted September 29, 2013 my php level still beginner Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451694 Share on other sites More sharing options...
Ch0cu3r Posted September 29, 2013 Share Posted September 29, 2013 (edited) I guess logged_in is a function? Then you have the parenthesis's (these are the ( and ) characters ) in the wrong place remove the red character (wrong place) and add the blue character (correct place) if (logged_in)() === true){ wrong ^ ^ right Edited September 29, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451695 Share on other sites More sharing options...
daruga Posted September 29, 2013 Author Share Posted September 29, 2013 thank you Ch0cu3r for help.. Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451696 Share on other sites More sharing options...
daruga Posted September 29, 2013 Author Share Posted September 29, 2013 <?php function logged_in() { return (isset($_SESSION['user_id'])) ? true : false; } function user_exists ($username) { $username = sanitize($username); return(mysql_result(mysql_query ("SELECT COUNT(user_id) FROM users WHERE username = '$username'"), 0) == 1) ? true : false; } function user_active($username){ $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT(user_id) FROM users WHERE username = '$username' AND active = 1"), 0) == 1) ? true : false; } function user_id_from_username($username) { $username = sanitize($username); return mysql_result(mysql_query("SELECT user_id FROM users WHERE username ='$username'"), 0, 'user_id'); } function login ($username, $password) { $user_id = user_id_from_username($username); $username = sanitize($username); $password = md5($password); return (mysql_result(mysql_query("SELECT COUNT(user_id) From users WHERE username = '$username' AND password = '$password'"), 0) ==1) ? $user_id : false; } ?> <aside> <?php if (logged_in() === true) { include 'includes/widgets/loggedin.php'; } else { include "includes/widgets/login.php"; } ?> </aside> Fatal error: Call to undefined function logged_in() in C:\wamp\www\mkjb\includes\aside.php on line 4 Call Stack # Time Memory Function Location 1 0.0008 140912 {main}( ) ..\register.php:0 2 0.0011 142336 include('C:\wamp\www\mkjb\includes\overall\overallheader.php') ..\register.php:1 3 0.0020 144880 include( 'C:\wamp\www\mkjb\includes\aside.php' ) ..\overallheader.php:8 could u help me fix this...i try different method it give same result Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451707 Share on other sites More sharing options...
Ch0cu3r Posted September 29, 2013 Share Posted September 29, 2013 (edited) In what file is the logged_in() function located? Is it in the same file as aside.php? If it is not you need to include the file that contains this function before you can use it. Edited September 29, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/282524-need-help-with-login-proble-phpmyadmin/#findComment-1451711 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.