Error in php news system using txt

Parse error: syntax error, unexpected T_VARIABLE

Page 1 of 1

5 Replies - 1452 Views - Last Post: 28 July 2009 - 02:36 PM Rate Topic: -----

#1 greatdragon   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 08-November 06

Error in php news system using txt

Post icon  Posted 28 July 2009 - 02:01 PM

Form for add news:
<form action="var.php" method="post">
	 <input name="titulo" type="text" class="addTitulo" value="T&iacute;tulo" />
	  <textarea name="noticia" cols="60" rows="12" class="addNews">Conte˙do</textarea>
	  <input name="input" type="submit" class="buttonNews" value="Enviar" /></form>


var.php
$f = fopen(tabela.txt,"a+",0);
$titulo = ($_POST['titulo']);
$noticia = ($_POST['noticia']);
$linha = $titulo.":"$noticia":/n";
fwrite($f,$linha,strlen($linha));
$fclose($f);
?>


when I try to add something this error is shown:
"Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\loja\var.php on line 5"

thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Error in php news system using txt

#2 RPGonzo   User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Error in php news system using txt

Posted 28 July 2009 - 02:03 PM

change

$linha = $titulo.":"$noticia":/n";



to

$linha = $titulo . ":" . $noticia . ":/n";



you'll notice you were missing some . which were making the variables throw your error

This post has been edited by RPGonzo: 28 July 2009 - 02:04 PM

Was This Post Helpful? 0
  • +
  • -

#3 greatdragon   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 08-November 06

Re: Error in php news system using txt

Posted 28 July 2009 - 02:04 PM

aa
I change
$linha = $titulo.":"$noticia":/n";
to
$linha = $titulo.":".$noticia":/n";
and now thre is another error:
"Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\loja\var.php on line 5"
Was This Post Helpful? 0
  • +
  • -

#4 RPGonzo   User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Error in php news system using txt

Posted 28 July 2009 - 02:07 PM

Your still missing one ... copy and paste this exactly

$linha = $titulo . ":" . $noticia . ":/n";



thats a main reason i always always space out between the joining periods ... so that you can CLEARLY see them there ...
Was This Post Helpful? 0
  • +
  • -

#5 greatdragon   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 08-November 06

Re: Error in php news system using txt

Posted 28 July 2009 - 02:25 PM

I am using like this now:
<?php
$f = fopen(tabela.txt,"a+",0);
$linha = $titulo . ":" . $noticia . ":/n";
fwrite($f,$linha,strlen($linha));
$fclose($f);
?>


and getting this error:

Quote

"Fatal error: Function name must be a string in C:\xampp\htdocs\loja\var.php on line 5"

This post has been edited by greatdragon: 28 July 2009 - 02:25 PM

Was This Post Helpful? 0
  • +
  • -

#6 RPGonzo   User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Error in php news system using txt

Posted 28 July 2009 - 02:36 PM

you have a $ on your fclose() function ...

<?php
$f = fopen(tabela.txt,"a+",0);
$linha = $titulo . ":" . $noticia . ":/n";
fwrite($f,$linha,strlen($linha));
fclose($f);
?>



as a bit extra i would enclose the file name in quotes to insure no more issues ..

<?php
$f = fopen("tabela.txt","a+",0);
$linha = $titulo . ":" . $noticia . ":/n";
fwrite($f,$linha,strlen($linha));
fclose($f);
?>




This last bit is the complete code tested and working ...
<?php
$f = fopen("tabela.txt","a+",0);
$titulo = ($_POST['titulo']);
$noticia = ($_POST['noticia']);
$linha = $titulo . ":" . $noticia . ": \n";
fwrite($f,$linha,strlen($linha));
fclose($f);
?>


This post has been edited by RPGonzo: 28 July 2009 - 02:43 PM

Was This Post Helpful? 1

Page 1 of 1