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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.