-3
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\project\homepage.php on line 235

I want to echo my post in my wall if it has a content to post but if the length of my textarea is <0 or above to 160 I want to echo an error then redirect to same page. But if it has a content I want to echo that messages.

<?php 

//build query for displaying post messages                                  
$strQuery = "SELECT * FROM freedom_wall ORDER BY id DESC";

// execute
if ($hQuery = $objConnection->query($strQuery)) {
//get data
while($row=$hQuery->fetch_assoc()){
$link_address = "files.php";


?>  
<hr>    
<?php 

$postbody = $_POST['post_msg'];
if (strlen($postbody) > 160 || strlen($postbody) < 1) {
echo ("<script LANGUAGE='JavaScript'>
window.alert('Nothing to post!');
window.location.href='homepage.php';
</script>");
} else { //This is where I received the error i'm hard enough in using ' and " with concats
echo   "<br><h4><?php echo $row['username']; ?></h4>
<p><h4><?php echo $row['post_msg']; ?></h4>
<?php echo '<a href='".$link_address."'>".$row["post_file"]."</a>';?>
</p>";
?>

Please help me                                  

2 Answers2

0

This should fix the issue:

<?php $strQuery = "SELECT * FROM freedom_wall ORDER BY id DESC"; ?>
<?php if ($hQuery = $objConnection->query($strQuery)): ?>
    <?php while($row = $hQuery->fetch_assoc()): ?>
        <?php $link_address = "files.php"; ?>
        <hr>
        <?php
            $postbody = $_POST['post_msg'];
            if (strlen($postbody) > 160 || strlen($postbody) < 1) {
                echo ("<script LANGUAGE='JavaScript'>
                window.alert('Nothing to post!');
                window.location.href='homepage.php';
                </script>");
            } else { 
                echo   "<br><h4>" . $row['username'] . "</h4>
                <p><h4>" . $row['post_msg'] . "</h4>
                <a href='" . $link_address . "'>" . $row["post_file"] . "</a>
                </p>";

            }
        ?>
    <?php endwhile; ?>
<?php endif; ?>
hungersoft
  • 531
  • 4
  • 8
  • Thank you sir it helps me a lot. I gonna study the construction of that code. Sir it produce an error ": syntax error, unexpected '}', expecting end of file in C:\xampp\htdocs\project\homepage.php on line 235" } ?> This is where the error has been expected to fix. – Nigel Perey Mar 17 '18 at 04:44
  • The above code seems alright. You will have to show me your complete code and how you've used the changes i made to know what the error is. – hungersoft Mar 17 '18 at 04:52
  • Hungersoft I posted the whole code including your solution for this page. Please help me. I understand now your construction but still I can't find where that error comes from. – Nigel Perey Mar 17 '18 at 06:03
  • Remove `` that is after my code. If this still doesn't fix, give me the latest error message and the update the code here as well. – hungersoft Mar 17 '18 at 06:08
  • Sure. Did you already seen my previous post? It contains the whole code. – Nigel Perey Mar 17 '18 at 06:17
  • Yes, that is why I asked you to remove `` from your code and then upload the new code here. – hungersoft Mar 17 '18 at 06:18
  • After I remove your code. It goes to `if (strlen($postbody) > 160 || strlen($postbody) < 1) { echo ("");` And having an exception (unlimited loop) on that code – Nigel Perey Mar 17 '18 at 06:23
  • I will update you with the whole code. – Nigel Perey Mar 17 '18 at 06:23
  • I believe the code you posted is of the file homepage.php, which means you are loading it over and over and every time it goes to the same part of the loop. Remove `window.location.href='homepage.php';` and then try. – hungersoft Mar 17 '18 at 06:27
  • I remove it. Then it releases this code. `Notice: Undefined index: post_msg in C:\xampp\htdocs\project\homepage.php on line 219` – Nigel Perey Mar 17 '18 at 06:29
  • The error message clearly describes what the error is, can't you understand that? Add an `isset` function check to make sure `post_msg` is set. – hungersoft Mar 17 '18 at 06:34
  • Also I'm having a problem with my textarea because when I load the `homepage.php` The placeholder in textarea are not displaying. I think it has a whitespace and when I deleted those whitespaces the placeholder will now appear. I already check my value in that textarea and it was empty but still there are whitespaces. – Nigel Perey Mar 17 '18 at 06:35
  • I already added that – Nigel Perey Mar 17 '18 at 06:36
  • I will show you now the code. It was okay. But the whitespaces I can't fix it. – Nigel Perey Mar 17 '18 at 06:36
  • I don’t know what you mean – hungersoft Mar 17 '18 at 06:37
  • `
    – Nigel Perey Mar 17 '18 at 06:39
  • That is because your closing tag `` has one empty line above it. Place the tag `` on the same line as ` – hungersoft Mar 17 '18 at 06:45
  • Thank you sir for helping me. What can I do for you? I'm just a newbie user here at stackoverflow. When I visiting profiles I can see reputations. – Nigel Perey Mar 17 '18 at 06:53
  • You can accept my answer – hungersoft Mar 17 '18 at 06:58
0

You have not closed curly braces of all starting curly braces. Use below code that I have fixed for you.

<?php 

//build query for displaying post messages                                  
$strQuery = "SELECT * FROM freedom_wall ORDER BY id DESC";

// execute
if ($hQuery = $objConnection->query($strQuery)) {
//get data
while($row=$hQuery->fetch_assoc()){
    $link_address = "files.php";


    ?>  
    <hr>    
    <?php 

    $postbody = $_POST['post_msg'];
    if (strlen($postbody) > 160 || strlen($postbody) < 1) {
    echo ("<script LANGUAGE='JavaScript'>
    window.alert('Nothing to post!');
    window.location.href='homepage.php';
    </script>");
    } else { //This is where I received the error i'm hard enough in using ' and " with concats
    echo   "<br><h4><?php echo $row['username']; ?></h4>
    <p><h4><?php echo $row['post_msg']; ?></h4>
    <?php echo '<a href='".$link_address."'>".$row["post_file"]."</a>';?>
    </p>";

    }
}
}
?>
Arshad Hussain
  • 765
  • 5
  • 22