Page 1 of 1

Simple idea Stupid error?!!!! (stat script)

Posted: Mon Dec 06, 2004 6:54 am
by L33
right im pretty new to php so any help on this little error would be great 8O

the following code gives out this error :-
Parse error: parse error, unexpected $ in /usr/home/l33/public_html/stat.php on line 23

A connection to the db is already set but i aint showing that ;), anyways heres the code:-

Code: Select all

<?
//Stat Script
$pagename = $_SERVER['PHP_SELF'];
$sql = "SELECT * FROM l33_stat WHERE (pagename = '$pagename')";
$res = mysql_query($sql) or die(mysql_error());
//if to check if there is a page by that name in db
if (!$res) { 
	$numofhits = "1";
	$thedate = date('H:i F j, Y');
		$sql = "INSERT INTO l33_stat (pagename,numofhits,lasthit) VALUES ('$pagename','$numofhits','$thedate')";
		$res = mysql_query($sql) or die(mysql_error());
			exit();
} else {
	while ($row = mysql_fetch_array($res, MYSQL_NUM)){
		$numofhits = $row['numofhits'];
		$last = $row['lasthit'];
		//$numberofhits = $numberofhits + 1;
			$sql = "UPDATE l33_stat SET numberofhits = '$numberofhits'  WHERE pagename = '$pagename'";
			$res = mysql_query($sql) or die(mysql_error());
	
}
?>
thanks for taking the time to at least look at the code
L33

Posted: Mon Dec 06, 2004 7:02 am
by harsha
I Obseverd:

1. Else Loop brace was not closed.
2. use {} while using a variable in side a string
$message = "My name is {$name}".

Code: Select all

$pagename = $_SERVER['PHP_SELF'];
$sql = "SELECT * FROM l33_stat WHERE pagename=".$pagename;
$res = mysql_query($sql) or die(mysql_error());

if (!$res) { 
    $numofhits = 1;
    $thedate = date('H:i F j, Y');
        $sql = "INSERT INTO l33_stat (pagename,numofhits,lasthit) VALUES ('{$pagename},'{$numofhits}','{$thedate}')";
        $res = mysql_query($sql) or die(mysql_error());
            exit();
} else {
    while ($row = mysql_fetch_array($res, MYSQL_NUM)){
        $numofhits = $row['numofhits'];
        $last = $row['lasthit'];
            $sql = "UPDATE l33_stat SET numberofhits = '{$numberofhits}'  WHERE pagename = '{$pagename}'";
            $res = mysql_query($sql) or die(mysql_error());
    
		}
	}
:-)

Posted: Mon Dec 06, 2004 7:05 am
by L33
:roll: doh , thanks for the reply , keep missing silly little things like that
regards L33

Posted: Mon Dec 06, 2004 7:09 am
by harsha
All the best