GrizRule Posted March 4, 2014 Share Posted March 4, 2014 I have this parse error but I do not know where exactly the script went wrong. I am trying to put the contents of $new_message into another file that gets created. And yes, the PHP code that is inside $new_message should be there, I want it to also be inserted into the file that gets created. Error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\Hosting\12059488\html\blog\makepost\makepost.php on line 36 $new_message = "<h1 class=\"title\">$title</h1><p> $post <br><br>-$name <br>$date at $time<br><a href=\"reply.php?n=blogentry$n.php\">Comment</a> <?php session_start(); if($_SESSION[\'USERNAME\'] == \'TEP\') { echo \"<a href=\"../makepost/changepost.php?posts=blogentry$n.php\">Edit</a>\"; } ?></p><hr>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/286694-parse-error-unexpected-t_encapsed_and_whitespace/ Share on other sites More sharing options...
jairathnem Posted March 4, 2014 Share Posted March 4, 2014 I think the error is because of the backslash in line 36. try this if($_SESSION['USERNAME'] == 'TEP') { Quote Link to comment https://forums.phpfreaks.com/topic/286694-parse-error-unexpected-t_encapsed_and_whitespace/#findComment-1471431 Share on other sites More sharing options...
GrizRule Posted March 4, 2014 Author Share Posted March 4, 2014 After trying that code, it still gave me the same error Quote Link to comment https://forums.phpfreaks.com/topic/286694-parse-error-unexpected-t_encapsed_and_whitespace/#findComment-1471433 Share on other sites More sharing options...
jairathnem Posted March 4, 2014 Share Posted March 4, 2014 post the full code. Quote Link to comment https://forums.phpfreaks.com/topic/286694-parse-error-unexpected-t_encapsed_and_whitespace/#findComment-1471434 Share on other sites More sharing options...
GrizRule Posted March 4, 2014 Author Share Posted March 4, 2014 (edited) <?php error_reporting(E_ALL); ini_set('display_errors', 1); session_start(); //Starts session to retrieve username $name = $_SESSION['USERNAME']; // Retrieving session username if($_SESSION['USERNAME'] == 'TEP') { $name = "The Elemental Programmer"; } else { $name = $_SESSION['USERNAME']; } $post = $_POST['post']; // The Blog entry itself $date = date("m/d/y"); $time = date("h:i A"); $title = $_POST ['title']; // Title of the blog entry $n = 994; $i = 0; $dir = '../entries/'; if ($handle = opendir($dir)) { while (($file = readdir($handle)) !== false){ if (!in_array($file, array('.', '..')) && !is_dir($dir.$file)) $i++; $n = 994 - $i; } } $new_message = "<h1 class=\"title\">$title</h1><p> $post <br><br>-$name <br>$date at $time<br><a href=\"reply.php?n=blogentry$n.php\">Comment</a> <?php session_start(); if($_SESSION['USERNAME'] == 'TEP') { echo \"<a href=\"../makepost/changepost.php?posts=blogentry$n.php\">Edit</a>\"; } ?></p><hr>\n"; // Creates file for blog entry $open_file = fopen("../entries/blogentry".$n.".php", "x"); // Enters new entry and strips the slashes fputs($open_file, stripslashes($new_message)); // Close the file fclose($open_file); ?> Edited March 4, 2014 by GrizRule Quote Link to comment https://forums.phpfreaks.com/topic/286694-parse-error-unexpected-t_encapsed_and_whitespace/#findComment-1471435 Share on other sites More sharing options...
jairathnem Posted March 4, 2014 Share Posted March 4, 2014 I see the following errors : 1. $new_message is a variable - on line 33 it is missing the end semi-colon. 2. no need to open php tag inside another php - you can just echo the HTML stuff. Quote Link to comment https://forums.phpfreaks.com/topic/286694-parse-error-unexpected-t_encapsed_and_whitespace/#findComment-1471436 Share on other sites More sharing options...
GrizRule Posted March 4, 2014 Author Share Posted March 4, 2014 I do not want that PHP code inside $new_message to be executed inside the script above, I want it to be executed in the new file that it made when the script above is ran. That is why I put the opening php tag inside the echo. I want it inside the new file Quote Link to comment https://forums.phpfreaks.com/topic/286694-parse-error-unexpected-t_encapsed_and_whitespace/#findComment-1471437 Share on other sites More sharing options...
jairathnem Posted March 4, 2014 Share Posted March 4, 2014 I dont know what use that is. But if you want to acheive that add it all to a single line and use escape sequence like \n,\t. But not sure why you want to do this. Quote Link to comment https://forums.phpfreaks.com/topic/286694-parse-error-unexpected-t_encapsed_and_whitespace/#findComment-1471438 Share on other sites More sharing options...
Ch0cu3r Posted March 4, 2014 Share Posted March 4, 2014 (edited) You appear to be creating individual php files for each post. This I do not recommend You should be storing the posts in some sort of database. You'd then use PHP to retrieve the contents of the post from the database. Like this tutorial shows http://www.daveismyname.com/creating-a-blog-from-scratch-with-php-bp Edited March 4, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/286694-parse-error-unexpected-t_encapsed_and_whitespace/#findComment-1471443 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.