Jump to content

Help would be lovely! Config Problems


Cheyenne

Recommended Posts

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]'");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/125201-help-would-be-lovely-config-problems/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.