我有一个表单,可以将帖子添加到数据库表中,并在此表中创建类别,并在“添加帖子”表单中添加一个选项,用于在添加帖子时选择类别。它在我的其他网站上有效,只是为了尝试一些新事物,但对于我的主要项目来说,它不起作用,并且我使用具有相同表名称的相同代码。有人可以检查代码并告诉我错误在哪里吗?
这就是我的整个 ADDposts 表单:
<?php
include 'includes/connect.php';
if(isset($_POST['add']))
{
$time = time();
$title = htmlspecialchars($_POST['title']);
$content = strip_tags($_POST['content']);
$post_image= $_FILES['image'] ['name'];
$image_tmp= $_FILES['image'] ['tmp_name'];
$q = "INSERT INTO posts(post_title,post_content,post_author,added,post_image) VALUES('$title','$content','Papazov','$time','$post_image')";
mysql_query($q) or die (mysql_error());
}
?>
<!DOCTYPE html>
<?php include "hhh.html"; ?> <br /><br />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MatchZone</title>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
</head>
<body>
<p>
<form method="post" action="Addpost.php" enctype="multipart/form-data">
Заглавие: <input type="text" name="title" /><br/><br/>
<tr>
<td align="right">Preview:</td>
<td><input type="text" name="preview" size="30"></td>
</tr>
<br />
<br />
<tr>
<td align="right">Сложи снимка: </td>
<td><input type="file" name="image"></td>
</tr>
<br/><br/>
Категория: <select name="category">
<?php
$q = mysql_query("SELECT*FROM categories") or die (mysql_error());
while($c = mysql_fetch_assoc($q))
{
print '<option value="'.$c['cat_id'].'">'.$c['name'].'</option>\n';
}
?>
</select><br />
<br />
<textarea class="ckeditor" name= "content" cols="30" rows="10"></textarea><br />
<input type="submit" name="add" value="Добави" />
</form>
</p>
</body>
</html>
最佳答案
你关闭了选择标签吗?如果您可以显示插入数据库的部分会有帮助
关于php - 将帖子添加到表单数据库类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21470081/