Jump to content

parse error, unexpected $


IceDragon

Recommended Posts

I keep getting

 

Parse error: parse error, unexpected $ in /home/www/mywebsite.com/log.php on line 38

 

line 38 is the last line of log.php (</html>) and I don't have a clue why I keep getting an error..

 

log.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Logs 2</title>
</head>

<body>
<?php

// DATABASE INFORMATION
$user="myusername";
$host="myhost";
$password="mypass";
$database="mydb";

// CONNECTING TO YOUR DATABASE
$connection = mysql_connect($host,$user,$password)
    or die ("Couldn't connect to server");
$db = mysql_select_db($database,$connection)
    or die ("Couldn't select database");

// GETTING THE VISITOR INFORMATION FROM YOUR TABLE
$query = mysql_query("SELECT * FROM Log ORDER BY ID DESC");

// GETS AND DISPLAYS THE ROWS IN YOUR TABLE
while ( $row = mysql_fetch_array($query) )
{
  $id = $row['ID'];
  $date = $row['Datum'];
  $ip = $row['IP'];
  $lang = $row['Jezik'];
  $referer = $row['Referer'];
  $browser = $row['Browser'];
  $currentURL = $row['Trenutni URL'];
?>
</body>
</html>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Logs 2</title>
</head>

<body>
<?php

// DATABASE INFORMATION
$user="myusername";
$host="myhost";
$password="mypass";
$database="mydb";

// CONNECTING TO YOUR DATABASE
$connection = mysql_connect($host,$user,$password)
    or die ("Couldn't connect to server");
$db = mysql_select_db($database,$connection)
    or die ("Couldn't select database");

// GETTING THE VISITOR INFORMATION FROM YOUR TABLE
$query = mysql_query("SELECT * FROM Log ORDER BY ID DESC");

// GETS AND DISPLAYS THE ROWS IN YOUR TABLE
while ( $row = mysql_fetch_array($query) )
{
  $id = $row['ID'];
  $date = $row['Datum'];
  $ip = $row['IP'];
  $lang = $row['Jezik'];
  $referer = $row['Referer'];
  $browser = $row['Browser'];
  $currentURL = $row['Trenutni URL'];
} //<----------RIght Here
?>
</body>
</html>

You forgot to close your loop.

ok thanks.

I have another problem now..

 

I get a the mysql_query() error on line 27..

 

while ( $row = mysql_fetch_array($query) )

 

i added the 'or die(mysql_error());' to that line.. and now I get the

 

Table 'mydbusername.Log' doesn't exist

 

 

here's the sql file..

CREATE TABLE `Log` (
  `ID` int( NOT NULL auto_increment,
  `Datum` datetime NOT NULL default '0000-00-00 00:00:00',
  `IP` varchar(20) NOT NULL default '',
  `Jezik` varchar (20) NOT NULL default '',
  `Referer` varchar(255) NOT NULL default '',
  `Browser` varchar(255) NOT NULL default '',
  `Trenutni URL` varchar (255) NOT NULL default '',
  PRIMARY KEY  (`ID`)
)

i meant to ask why doesn't it exist/what have i missed..

I can post the other php code related to this if it helps.

 

Edit:

the other code:

   <?php


$user="myusername";
$host="myhost";
$password="mypass";
$database="mydb";


$connection = mysql_connect($host,$user,$password)
    or die ("Couldn't connect to server");
$db = mysql_select_db($database,$connection)
    or die ("Couldn't select database");


$ip = $_SERVER['REMOTE_ADDR'];
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$referer = $_SERVER['HTTP_REFERER'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$currentURL = $_SERVER['REQUEST_URI'];

$query = mysql_query("INSERT INTO Log VALUES ('',now(),'$ip',$lang','$referer','$browser','$currentURL')");

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.