Jump to content

Syntax error, unexpected T_STRING


Go to solution Solved by requinix,

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

  • Solution

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.

Edited by boompa

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.