Jump to content

Parse error: syntax error


guybrown

Recommended Posts

Hi all

 

I'm new to programming and this forum and know very little about php. Any help would be greatly appreciated and I look forward to contributing and supporting others as my knowledge increases.

 

I am trying to get a 'counter' php file working on my localhost. When I run the php file in chrome I get the following error:

 

Parse error: syntax error, unexpected '$result' (T_VARIABLE), expecting ',' or ';' in C:\xampp\htdocs\database\counter.php on line 8

 

My php file contains the following:

 

 

<?php
require($_SERVER["DOCUMENT_ROOT"]."/database/config/db_config.php");
$connection = @mysql_connect($db_host,$db_user, $db_password) or die("error connecting");
mysql_select_db($db_name, $connection);
 
$query = "SELECT * FROM counter";
echo $query
$result = mysql_query($query, $connection) or die(mysql_error());
echo $result
$views = mysql_result($result, 0, "num_views");
echo $views
 
$views++;
 
$query = "UPDATE counter SET num_views = $views";
mysql_query($query, $connection) or die(mysql_error());
 
echo "This page has been viewed ".$views." times.";
?>

 

I created the counter table in phpmyadmin and it has the following details:

 

 


# Name Type Collation Attributes Null Default Extra Action 1 num_views int(5)   UNSIGNED No 0   dot.gif Change dot.gif Drop dot.gif Browse distinct values

 

Any help appreciated.

 

Regards,

 

Guy Brown

counter.php

Link to comment
https://forums.phpfreaks.com/topic/278546-parse-error-syntax-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.