By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,977 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,977 IT Pros & Developers. It's quick & easy.

php parse error, unexpected T_VARIABLE...

P: 2
got this annoying error

I'm completly new to php... and i have no clue what is wrong here, from what i can tell there is nothing rong with this code... but that isn't what the borwser say :P

Parse error: parse error, unexpected T_VARIABLE in main.php on line 15

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title></title>
<head/>
<body style="background-color: transparent">
<?php
$file=fopen("news.txt","r") or exit("Unable to open file!");
$first = 1
$ordn = fgetc($file);
fgets($file);
while (!feof($file))
{
if $first = 1
{
$check = fgetc($file);
$first = 0
}
if $check = "_"
{
$check = fgetc($file);
}
if $check = $ordn
{
$ordn = $ordn - 1
while $check(!"_")
{
echo fgets($file);
$check = fgetc($file);
}
}
else
{
fgets($file);
$check = fgetc($file);
}
}
fclose($file);
?>
</body>
</html>

NEXT TIME ENCLOSE YOUR CODE WITHIN PHP, CODE OR HTML TAGS!! READ THE POSTING GUIDLINES BEFORE POSTING ANYTHING IN THIS FORUM! - Ronald :cool:
Nov 28 '06 #1
Share this Question
Share on Google+
4 Replies


P: 17
got this annoying error

I'm completly new to php... and i have no clue what is wrong here, from what i can tell there is nothing rong with this code... but that isn't what the borwser say :P

Parse error: parse error, unexpected T_VARIABLE in main.php on line 15

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title></title>
<head/>
<body style="background-color: transparent">
<?php
$file=fopen("news.txt","r") or exit("Unable to open file!");
$first = 1
$ordn = fgetc($file);
fgets($file);
while (!feof($file))
{
if $first = 1
{
$check = fgetc($file);
$first = 0
}
if $check = "_"
{
$check = fgetc($file);
}
if $check = $ordn
{
$ordn = $ordn - 1
while $check(!"_")
{
echo fgets($file);
$check = fgetc($file);
}
}
else
{
fgets($file);
$check = fgetc($file);
}
}
fclose($file);
?>
</body>
</html>
Hi bovanshi,

You have missed the required semicolons and the ( ) in your if () statements. Your if statement conditions should be always inside ( ) .
Here , is the right code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title></title>
<head/>
<body style="background-color: transparent">
<?php
$file=fopen("news.txt","r") or exit("Unable to open file!");
$first = 1;
$ordn = fgetc($file);
fgets($file);
while (!feof($file))
{
if ($first = 1)
{
$check = fgetc($file);
$first = 0;
}
if ($check = "_")
{
$check = fgetc($file);
}
if ($check = $ordn)
{
$ordn = $ordn - 1;
while ($check(!"_"))
{
echo fgets($file);
$check = fgetc($file);
}
}
else
{
fgets($file);
$check = fgetc($file);
}
}
fclose($file);

?>
</body>
</html>
This will work now.
YOU TOO SCRIPTEE!

NEXT TIME ENCLOSE YOUR CODE WITHIN PHP, CODE OR HTML TAGS!! READ THE POSTING GUIDLINES BEFORE POSTING ANYTHING IN THIS FORUM! - Ronald :cool:
Nov 28 '06 #2

P: 2
Thank you xD
Nov 28 '06 #3

P: 17
Thank you xD
You are welcome :)
Nov 29 '06 #4

P: 2
i am getting similar parse error and i can't understand where exactly the sintax is wrong...can you help?
the code is
<?php
require_once('db_login.php');
$sdbh = "";
$expire = 900;
function sess_open($save_path, $session_name){
global $dbhost, $dbuser, $dbpasswd, $sdbh;
if (! $sdbh = mysql_pconnect($dbhost, $dbuser, $dbpasswd)){
echo mysql_error();
exit;
}
return true;
}
function sess_close(){
return true;
}
function sess_read($key){
global $sdbh, $dbname, $tb_sessions;
$query = "
select
data
from
$tb_sessions
where
id = '$key'
and
expire > UNIX_TIMESTAMP()
";
$result = mysql_query($query);
if($record = mysql_fetch_row($result)){
return $record;
}else {
print (mysql_error());

}
function sess_write($key, $val){
global $sdbh, $dbname, $tb_sessions, $expire;
$value = addslashes($val);
$query = "
replace into
$tb_sessions
values (
'$key',
'$value',
UNIX_TIMESTAMP() + $expire
)
";
$result = mysql_query($query);
echo mysql_error();
return $result;
}
function sess_destroy($key){
global $sdbh, $dbname, $tb_sessions;
$query = "
delete from
$tb_sessions
where
id = '$key'
";
$result = mysql_query($query);
return $result;
}
function sess_gc($maxlifetime){
global $sdbh, $dbname, $tb_sessions;
$query = "
delete from
$tb_sessions
where
expire < UNIX_TIMESTAMP()
";
$result = mysql_query($query);
return mysql_affected_rows($sdbh);
}
session_set_save_handler("sess_open","sess_close", "sess_read","sess_write","sess_destroy","sess_gc") ;
session_start();
$sn = session_name();
$sid = session_id();

?>
Feb 25 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.