Guys I have 2 files. index.php and connect.php
I'm getting database connection error.
This is the error i got
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\wamp\www\index.php on line 3
Then i added the error detection code in the third line. I got the following message
No database selected
I'm sure i have database, username and password correct but don't understand why my database not selected. please anyone post solution
connect.php
<?
$DB_HOST = "localhost";
$DB_USER = "admin";
$DB_PASSWORD = "admin";
$DB_NAME = "minitaskr";
$timeoutseconds = 1200; // length of session, 20 minutes is the standard
$timestamp=time();
$timeout=$timestamp-$timeoutseconds;
$connect = mysql_connect($DB_HOST,$DB_USER,$DB_PASSWORD);
mysql_select_db($DB_NAME) or die("MySQL error: Could not connect to database.\n".mysql_error());
$session = mysql_query("SELECT * FROM members WHERE id = '$_SESSION[id]' AND password = '$_SESSION[password]'");
$session = mysql_fetch_array($session);
parse_str("$QUERY_STRING");
$db = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD) or die("Could not connect.");
if(!$db)
die("no db");
if(!mysql_select_db($DB_NAME,$db))
die("No database selected.");
if(!get_magic_quotes_gpc())
{
$_GET = array_map('mysql_real_escape_string', $_GET);
$_POST = array_map('mysql_real_escape_string', $_POST);
$_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
else
{
$_GET = array_map('stripslashes', $_GET);
$_POST = array_map('stripslashes', $_POST);
$_COOKIE = array_map('stripslashes', $_COOKIE);
$_GET = array_map('mysql_real_escape_string', $_GET);
$_POST = array_map('mysql_real_escape_string', $_POST);
$_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
?>
index.php
<?php session_start(); include("connect.php");
$result = mysql_query("SELECT * FROM sitesettings")or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$title = "".$row["domain"]." - ".$row["tagline"]."";
$reload = $_SERVER['PHP_SELF'];
$rpp = 18; // results per page
$adjacents = 4;
$page = intval($_GET["page"]);
if(!$page) $page = 1;
$siteurl = $row["site_url"];
}
include("header.php");
?>