webdevdea Posted July 20, 2013 Share Posted July 20, 2013 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>'; } Quote Link to comment https://forums.phpfreaks.com/topic/280335-syntax-error-unexpected-t_string/ Share on other sites More sharing options...
Solution requinix Posted July 20, 2013 Solution Share Posted July 20, 2013 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.""; Quote Link to comment https://forums.phpfreaks.com/topic/280335-syntax-error-unexpected-t_string/#findComment-1441458 Share on other sites More sharing options...
webdevdea Posted July 20, 2013 Author Share Posted July 20, 2013 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>'; } Quote Link to comment https://forums.phpfreaks.com/topic/280335-syntax-error-unexpected-t_string/#findComment-1441461 Share on other sites More sharing options...
webdevdea Posted July 20, 2013 Author Share Posted July 20, 2013 http://www.youtube.com/watch?v=Ji9nXnbal8c Quote Link to comment https://forums.phpfreaks.com/topic/280335-syntax-error-unexpected-t_string/#findComment-1441462 Share on other sites More sharing options...
boompa Posted July 20, 2013 Share Posted July 20, 2013 (edited) 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 July 20, 2013 by boompa Quote Link to comment https://forums.phpfreaks.com/topic/280335-syntax-error-unexpected-t_string/#findComment-1441479 Share on other sites More sharing options...
webdevdea Posted July 20, 2013 Author Share Posted July 20, 2013 I didnt copy and paste code, you cant do that off of youtube anyway, I worked through the tutorial, I have some other versions that were not working and I scrapped them all looked for an alternative and WOW how hateful.. Quote Link to comment https://forums.phpfreaks.com/topic/280335-syntax-error-unexpected-t_string/#findComment-1441490 Share on other sites More sharing options...
webdevdea Posted July 20, 2013 Author Share Posted July 20, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280335-syntax-error-unexpected-t_string/#findComment-1441491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.