PHP_SELF代码给出错误消息

时间:2018-01-13 21:40:19

标签: php mysql

我在这里有这个代码。它给了我一个语法错误错误,意外的T_STRING,期待','或者&#39 ;;'。我希望能够在同一页面上显示成功消息,而不是打开另一个页面。请帮忙。

} else {
    $query = "SELECT title, author, post, id FROM news_posts WHERE id=$id";
    $result = mysql_query($query);
    $num = mysql_num_rows($result);
    $row = mysql_fetch_array ($result, MYSQL_NUM);

    $title = $row['0'];
    $name = $row['1'];
    $message = $row['2'];

    if ($num == 1) {
    echo '
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <p><b>Post Title :</b><br />
    <input type="text" class="form-control" name="title" value="'.$title.'" /></p>
    <p><input type="hidden" name="name" size="15" maxlength="255" value="'.$name.'" /></p>
    <p><b>Post Message :</b><br /><textarea rows="7" class="form-control" name="message">'.$message.'</textarea></p>
    <p><input type="button" value="Back" onclick="history.back()">            <input type="submit" name="submit" value="Submit" /></p>
    <input type="hidden" name="submitted" value="TRUE" /></p>
    <input type="hidden" name="id" value="'.$id.'" /></form>';

    } else {
        echo 'News post could not be edited, please try again.';

    }

}
?>

1 个答案:

答案 0 :(得分:0)

这是因为PHP_SELF周围的单引号正在中断echo中的单引号。试试这个:

<form action="' . $_SERVER['PHP_SELF'] . '" method="post">