Hi all. I dowloaded a snipped and now I am having probs with it. I got it to work just great on my localhost, but when I try to submit to live host, I get this error when I run the setup.php file (creates db and stuff)
Here is the error that I get..
Error 1064 : You have an error in your SQL syntax near 'IF NOT EXISTS gfx_counter ( page char(100), count int(15) )' at line 1
Here is the code for the "setup.php"
<?
include ("counter.php");
$db_connect = mysql_connect($dbase_host,$dbase_user,$dbase_pass);
mysql_select_db($dbase_base);
$query = "CREATE TABLE IF NOT EXISTS $dbase_table
(
page char(100),
count int(15)
)";
$req = mysql_query($query);
if (!$req)
{
echo '<B>Error ' . mysql_errno() . ' :</B> ' . mysql_error();
exit;
}
mysql_close($db_connect);
?>
just in case, here is the code for the "counter.php"
<?php
// --------------------------------------- Your settings ------------------------------- //
//BTW, I changed this info to match my live settings
$dbase_host = "localhost";
$dbase_user = "root";
$dbase_pass = "";
$dbase_base = "mtliquidators";
$dbase_table = "gfx_counter";
// -------------------------------------------------------------------------------------- //
// --------------------------------------- MySQL Functions ------------------------------ //
function send_sql($dbase_base, $sql)
{
if(!$res=mysql_db_query($dbase_base, $sql))
{
echo mysql_error();
exit;
}
return $res;
}
function tab_out($result)
{
$nombre=mysql_num_fields($result);
echo "<table width=90% border=0 cellpadding='2' cellspacing='2'>";
echo "<tr bgcolor=#D0D0D0>";
for($i=0;$i<$nombre;$i++)
{
echo "<th>";
echo mysql_field_name($result,$i);
echo "</th>";
}
echo "</tr>";
echo "<tr>";
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
foreach ($row as $elem)
{
echo "<td bgcolor='#E8E8E8'><font size='-1'>$elem</font></td>";
}
echo "</tr>";
}
echo "</table>";
}
// ------------------------------------------------------------------------------------ //
function ShowCount($page)
{
global $dbase_host, $dbase_user, $dbase_pass, $dbase_base, $dbase_table;
$connect = @mysql_pconnect($dbase_host, $dbase_user, $dbase_pass);
mysql_select_db($dbase_base);
/* Grab the current count. */
$sql = "SELECT * FROM " . $dbase_table . " WHERE page='$page'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$count = $row["count"];
if (!($count))
{
$sql = "INSERT INTO " . $dbase_table . " values ('$page',1)";
$count = 1;
}
else
{
$count++;
$sql = "UPDATE " . $dbase_table . " set count='$count' where page='$page'";
}
/* Store the updated count */
if (!($store=mysql_query($sql)))
{
print mysql_error();
}
/* Return the Val */
return $count;
}
?>
Like I said above. I ran the "setup.php" on my localhost and it worked like a charm. I try to run it on the "live host" and it does not work. I went and created the table manually, but then it does not record the page that it is supposed to watch. Here is what it is supposed to do:
When a user comes to a certian page. I have a php code at the top of the page:
<?php
$page = $_SERVER['PHP_SELF'];
include('counter.php');
ShowCount($page);
?>
Then it is supposed to record into the database the page that was viewed, and how many hits. It shows me the hits, but not the page that was viewed. It combines ALL the pages into one record. But this only happens when I create the table manually. Does this make any sense?😕