tomfmason Posted July 8, 2006 Share Posted July 8, 2006 I have am trying(unsuccessfully) to create a login script. As suggested, I tried it with magic_quotes. I get the following error.[code]Warning: mysql_result(): supplied argument is not a valid MySQL result resource in test_login.php on line 13[/code]and here is the code[code=php:0]<?php include ('includes/db.php');array_pop($_POST); if ( get_magic_quotes_gpc() ) { $_POST= array_map('stripslashes', $_POST); } $username= mysql_real_escape_string(trim($_POST['username'])); $password= mysql_real_escape_string(trim($_POST['password'])); $sql= sprintf("SELECT COUNT(*) AS login_match FROM `users` WHERE `username` = '%s' AND `user_password`= '%s'", $username, $password); $res= mysql_query($sql); $login_match= mysql_result($res, 0, 'login_match'); if ( $login_match == 1 ) { echo "This test worked";} else { echo "This test did not work"; // not logged in }?>[/code]line 13[code=php:0]$login_match= mysql_result($res, 0, 'login_match');[/code]I am wondering if anyone can suggest as to why this is happening? Quote Link to comment https://forums.phpfreaks.com/topic/14012-mysql_result-supplied-argument-is-not-a-valid-mysql-result/ Share on other sites More sharing options...
tomfmason Posted July 8, 2006 Author Share Posted July 8, 2006 it was a simple error. I changed this line[b]from:[/b][code=php:0]$res= mysql_query($sql);[/code][b]to[/b][code=php:0]$res= mysql_query($sql) or die(mysql_error());[/code]This told me that user_password was not valid..lol. A simple errorI am running into another problem. It is not logining me in. I keep getting the error message[code=php:0]} else { echo "This test did not work";[/code]Any suggestions as to why this is not loging in? Quote Link to comment https://forums.phpfreaks.com/topic/14012-mysql_result-supplied-argument-is-not-a-valid-mysql-result/#findComment-54722 Share on other sites More sharing options...
tomfmason Posted July 8, 2006 Author Share Posted July 8, 2006 I tried echoing $login_match and it is returning 0. here is what I have for login match[code=php:0]$login_match= mysql_result($res, 0, 'login_match'); [/code]I am lost ??? Quote Link to comment https://forums.phpfreaks.com/topic/14012-mysql_result-supplied-argument-is-not-a-valid-mysql-result/#findComment-54724 Share on other sites More sharing options...
tomfmason Posted July 8, 2006 Author Share Posted July 8, 2006 LOL. It was rather simple. I needed to use mysql_num_rows instead of mysql_result. Now I need to work on the sessions.[b]*The Fix:[/b][code=php:0]<?php include ('includes/db.php');array_pop($_POST); if ( get_magic_quotes_gpc() ) { $_POST= array_map('stripslashes', $_POST); } $username= mysql_real_escape_string(trim($_POST['username'])); $password= mysql_real_escape_string(trim($_POST['password'])); $sql= sprintf("SELECT COUNT(*) AS login_match FROM `users` WHERE `username` = '%s' AND `password`= '%s'", $username, $password); $res= mysql_query($sql) or die(mysql_error()); $login_match= mysql_num_rows($res) or die(mysql_error()); if ( $login_match == 1 ) { echo 'This test worked';} else { print_r ($login_match); // not logged in }?>[/code]I hope this helps someone else in the future Quote Link to comment https://forums.phpfreaks.com/topic/14012-mysql_result-supplied-argument-is-not-a-valid-mysql-result/#findComment-54726 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.