View Full Version : MySQL and PHP trouble
moneybux
03-14-2008, 02:42 AM
I keep getting this error message on numberous pages on my site Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/moneybux/public_html/index.php on line (number of line on page).. and the culprit is the third line. I don't want to delete it yet. Does anyone have any ideas of what to do and how?
<?
$sql = "SELECT * FROM tb_config WHERE item='click' and howmany='1'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>
Medyman
03-14-2008, 03:28 AM
Posting in the PHP forum will probably get you better results.
codeexploiter
03-14-2008, 04:02 AM
It seems that you might be using incorrect table name or field names in your query. Make sure that the there is table contains fields named item and howmany. I've reproduced this error in my local PC when I mentioned the table names or field names incorrectly in my SQL query.
You can have a look at the code I've used
<?php
class database
{
private $db_handle;
private $user_name;
private $password;
private $data_base;
private $host_name;
private $sql;
private $results;
function __construct($host="localhost",$user,$passwd)
{
$this->db_handle = mysql_connect($host,$user,$passwd);
}
function dbSelect($db)
{
$this->data_base = $db;
if(!mysql_select_db($this->data_base, $this->db_handle))
{
error_log(mysql_error(), 3, "/phplog.err");
die("Error connecting to Database");
}
}
function executeSql($sql_stmt)
{
$this->sql = $sql_stmt;
$this->result = mysql_query($this->sql);
}
function returnResults()
{
return $this->result;
}
}
$user = "root";
$passwd = "";
$db = "testdb";
$sql = "SELECT * FROM users WHERE screenname = 'codeexploiter' AND password = '12345'";
$dbObject = new database($host,$user,$passwd);
$dbObject->dbSelect($db);
$dbObject->executeSql($sql);
$res = $dbObject->returnResults();
while($record = mysql_fetch_array($res))
{
echo "Screen Name: " . $record["ScreenName"] ." Password : " . $record["Password"] ."<br/>";
}
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.