好的,這是我的問題。我正在爲我的網站製作一個發佈腳本。但是這個腳本不起作用;腳本如下:PHP和MySQL發佈系統
<?php
// Make sure the user is logged in before going any further.
if (!isset($_SESSION['user_id'])) {
echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>';
exit();
}
else {
echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout.php">Log out</a>.</p>');
}
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (isset($_POST['submit'])) {
// Grab the profile data from the POST
$post1 = mysqli_real_escape_string($dbc, trim($_POST['post1']));
$query = "INSERT INTO ccp2_posts ('post') VALUES ('$post1')";
$error = false;
mysqli_close($dbc);
?>
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<legend>Posting</legend>
<label for="post">POST:</label>
<textarea rows="4" name="post1" id="post" cols="50">Write your post here...</textarea><br />
<input type="submit" value="submit" name="submit" />
</form>
</div>
<?php
include ("include/footer.html");
?>
</body>
</html>
當我提交表單時,數據庫中沒有任何內容顯示。幫助將是驚人的。謝謝。
快速提示:使用'action =「」'而不是將'$ _SERVER ['PHP_SELF']'放入動作中。如果你使用'RewriteRule'來生成「漂亮」的URL,這非常棒。 –
並且'session_start();'位於... –
檢查錯誤 –