Cheyenne Posted September 21, 2008 Share Posted September 21, 2008 Can you guys tell me what is wrong with this bit of coding. It keeps coming up with this error on line 9. Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.../public_html/config.php on line 9 File: Config.php <?php $dbhost = 'localhost'; $dbuser = 'master'; $dbpass = 'abc123'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Error!"); $dbname = 'master'; mysql_select_db($dbname); $logged = mysql_query("SELECT * from users WHERE id = '$_COOKIE[id]' and pass = '$_COOKIE[pass]'"); $logged = mysql_fetch_array($logged); <<<<<------ LINE 9 if(!$_GET[log]||$_GET[log]!=NO){ $time = time(); $ip = getenv("REMOTE_ADDR"); $insert_ip = mysql_query("INSERT into iplogs SET ip = '$ip', time = '$time', page = '$_SERVER[REQUEST_URI]'"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/125201-help-would-be-lovely-config-problems/ Share on other sites More sharing options...
JasonLewis Posted September 22, 2008 Share Posted September 22, 2008 This line: $logged = mysql_query("SELECT * from users WHERE id = '$_COOKIE[id]' and pass = '$_COOKIE[pass]'"); Is your problem. That error is the cause of a failure in your query. Try something like this instead: $logged = mysql_query("SELECT * from users WHERE id = '".$_COOKIE['id']."' and pass = '".$_COOKIE['pass']."'") or die(mysql_error()); The array's may have been causing a problem but it could also be that one of the COOKIE values is not being set properly. You should do error checking before you insert them straight into a MySQL query. Just basic things like checking if they are blank. Also note how I placed or die(mysql_error()) on the end of the query. If MySQL encounters an error it will stop running the script and tell you what the error is. Quote Link to comment https://forums.phpfreaks.com/topic/125201-help-would-be-lovely-config-problems/#findComment-647357 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.