Jump to content

Syntax error, unexpected T_STRING


webdevdea

Recommended Posts

I found a tutorial on youtube, but for some reason I get this error when I submit

its on line 14 $txt="<div id="mag"> <font color="red"> Messaggio inviato da: ".$utente."<br/><br/>"; 

<?php
$utente=htmlspecialchars($_POST["username"]);

$messaggio=htmlspecialchars($_POST["messaggio"]);
$data= date("d/m/Y M:i:s");
$msg="msg.TXT";

if ($utente==""){
	echo "Inserisci username";
} elseif($messaggio="") {
	echo "Inserisci un messaggio";
} else {
		 $guestbook = fopen($msg,"a");
		 $txt="<div id="mag"> <font color="red"> Messaggio inviato da: ".$utente."<br/><br/>";
		 $txt .="Messaggio: ".$messaggio. "<br/><br/>";
		 $txt .= "Messaggio scritto il:".$data."</font></div>";
		 fwrite($guestbook,$txt);
		 fclose($guestbook);
		 echo '<a href ="http://localhost/home.php">Torna ella home</a>';
		 }

Link to comment
https://forums.phpfreaks.com/topic/280335-syntax-error-unexpected-t_string/
Share on other sites

If you want to put "s inside a " string then you have to escape them. Otherwise how is PHP supposed to know where the end of the string is?

$txt="
Messaggio inviato da: ".$utente."

";Since you're using HTML you can also use 's instead, either for the string or for the quotes inside it.

$txt="
Messaggio inviato da: ".$utente."

";
$txt='
Messaggio inviato da: '.$utente."

";

Warning

Warning: fopen(msg.TXT) [function.fopen]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/php/send.php on line 13

Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/php/send.php on line 17

Warning: fclose() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/php/send.php on line 18
<?php
$utente=htmlspecialchars($_POST["username"]);

$messaggio=htmlspecialchars($_POST["messaggio"]);
$data= date("d/m/Y M:i:s");
$msg="msg.TXT";

if ($utente==""){
	echo "Inserisci username";
} elseif($messaggio="") {
	echo "Inserisci un messaggio";
} else {
		 $guestbook = fopen($msg,"a");
		 $txt='<div id="msg"> <font color="red"> Messaggio inviato da: ".$utente."<br/><br/>';
		 $txt .="Messaggio: ".$messaggio. "<br/><br/>";
		 $txt .= "Messaggio scritto il:".$data."</font></div>";
		 fwrite($guestbook,$txt);
		 fclose($guestbook);
		 echo '<a href ="http://localhost/home.php">Torna ella home</a>';
		 }

You don't learn anything by just copying and pasting (or poorly transcribing) code then running to experts for help you know.

 

http://pastebin.com/Fn1HMtsS

 

The error is right there.

 

 

 

Warning: fopen(msg.TXT) [function.fopen]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/php/send.php on line 13

 

The webserver runs as a restricted user and generally does not have write permissions to the filesystem unless you specifically allow it those permissions.

I did not copy and paste, I didnt even know that link was out there.. I was using Youtube as i said before

You don't learn anything by just copying and pasting (or poorly transcribing) code then running to experts for help you know.

 

http://pastebin.com/Fn1HMtsS

 

The error is right there.

 

 

 

 

The webserver runs as a restricted user and generally does not have write permissions to the filesystem unless you specifically allow it those permissions.

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.