Jump to content

Parse Error: Unexpected T_ENCAPSED_AND_WHITESPACE


GrizRule

Recommended Posts

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"; 
Link to comment
Share on other sites


<?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 by GrizRule
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by Ch0cu3r
Link to comment
Share on other sites

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.