我是php的初学者,我想要正确回应这个,但错误说

时间:2018-03-17 04:22:55

标签: php html mysql web

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

如果要发布内容我想在墙上回复我的帖子,但如果我的textarea的长度<0或者大于160我想要回显错误然后重定向到同一页面。但如果它有内容我想回复那些消息。

<?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 个答案:

答案 0 :(得分:0)

这应解决问题:

<?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; ?>

答案 1 :(得分:0)

你还没有关闭所有起始花括号的花括号。使用我为您修复的代码。

<?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>";

    }
}
}
?>