I'm using MySQL with PHP (just learned MySQL so bear with me).
Here's a two part program:
Test.php:
<html>
<body>
<?php
require("common.php");
CalculateScore(1);
?>
</body>
</html>
Common.php:
<?php
//Global variables
$Sitename="Toplist";
$Siteurl="";
$Links_per_page="50";
$Base_site_url="localhost";
//MySQL stuff
$host="localhost";
$user="root";
$password="pass32";
$database="xtopsites";
//Functions_begin
//Score Calculation
function CalculateScore($id) {
mysql_connect($host, $user, $password);
mysql_select_db($database);
$querytest="insert into sitestats (id, arate, urate, inhits) values (1, 5, 5, 500)";
mysql_query($querytest);
$sql = "select urate, arate, inhits from sitestats where id = $id";
$r = mysql_query($sql);
$row = mysql_fetch_array($r);
$arate = $row[arate];
$urate = $row[urate];
$inhits = $row[inhits];
if ($hits > 3000) { $hits = 3000; }
$score = (($arate * 5) + ($urate * 2) + ($inhits / 100));
echo($score);
//$sql = "update sitestats set score=$score where id = $id";
//mysql_query($sql);
}
?>
When I run test.php I get this:
Warning: Supplied argument is not a valid MySQL result resource in common.php on line
27
0
Here are lines 25-27:
25: $sql = "select urate, arate, inhits from sitestats where id = $id";
26: $r = mysql_query($sql);
27: $row = mysql_fetch_array($r);
I thought using the result identifier returned by mysql_query in mysql_fetch_array was
perfectly legal.
Please help out :)
Thanks alot.