100 credits to the one who fix this php

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
Soooo something is wrong again...

PHP:
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server ");
mysql_select_db("$db_name")or die("cannot select DB")

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
$counter=$rows['counter'];

// if have no counter value set counter = 1
if(empty($counter)){
$counter=1;
$sql1="INSERT INTO $tbl_name(counter) VALUES('$counter')";
$result1=mysql_query($sql1);
}

echo $counter;
echo "people has played our games. ";


mysql_close();
?>

I get this error: Parse error: syntax error, unexpected T_VARIABLE in /home/viggeswe/public_html/flash/counterh.php on line 12

Line 12 is
PHP:
$sql="SELECT * FROM $tbl_name";

It isn't line 12 here because I deleted the password and username thing at the top.

And yes. Everything I had input in the code is correct. And I have deleted the add hit on this one because I want to count the game plays and not the main page hits.
Edit:
Ok I give 100 credits for the one who fix it
 
Last edited:

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
I sad I already had done that but I don't want to post all my database password etc. The table name is there. Btw, this is what I use:
PHP:
$tbl_name="counter"; // Table name
And I have created the table.
 
Last edited:

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
PHP:
<title>Untitled Document</title><?php
$host="localhost"; // Host name
$username="*deleted*"; // Mysql username
$password="*deleted*"; // Mysql password
$db_name="viggeswe_phpbb"; // Database name
$tbl_name="counter"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server ");
mysql_select_db("$db_name")or die("cannot select DB")

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
$counter=$rows['counter'];

// if have no counter value set counter = 1
if(empty($counter)){
$counter=1;
$sql1="INSERT INTO $tbl_name(counter) VALUES('$counter')";
$result1=mysql_query($sql1);
}

echo $counter;
echo "people has played our games. ";

mysql_close();
?>
 

supajason

Member
Messages
288
Reaction score
2
Points
18
change
PHP:
mysql_select_db("$db_name")or die("cannot select DB")

to

PHP:
mysql_select_db("$db_name")or die("cannot select DB");
 

galaxyAbstractor

Community Advocate
Community Support
Messages
5,508
Reaction score
35
Points
48
Ok, It worked now. I give you the credits if you fix this too:

PHP:
<title>Untitled Document</title><?php
$host="localhost"; // Host name
$username="************"; // Mysql username
$password="************"; // Mysql password
$db_name="viggeswe_phpbb"; // Database name
$tbl_name="counter"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server ");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
$counter=$rows['counter'];

// if have no counter value set counter = 1
if(empty($counter)){
$counter=1;
$sql1="INSERT INTO $tbl_name(counter) VALUES('$counter')";
$result1=mysql_query($sql1);
}

// count more value
$addcounter=$counter+1;
$sql2="update $tbl_name set counter='$addcounter'";
$result2=mysql_query($sql2);

mysql_close();
?>

It adds 2 instead of 1 when I visit the page once.
 

supajason

Member
Messages
288
Reaction score
2
Points
18
try

PHP:
$addcounter = $counter + "1";

or

PHP:
$counter++;
$sql2="update $tbl_name set counter='$counter'";
 
Last edited:
Top