无法将帖子插入数据库表 [英] Post can't be inserted to database table

查看:173
本文介绍了无法将帖子插入数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名新的PHP学习者,我曾尝试过几次将代码插入表中.我认为我的php代码有错误.但是我自己却无法解决

我尝试过的事情:

I am new PHP learner and I''ve attempted several times to insert my codes to table.I think there is mistake in my php codes.But I wasn''t able to solve it myself

What I have tried:

<pre><?php
include "config.php";
include "db.php";

$db = new database();


$query = "SELECT * FROM categories";
$cats = $db ->select($query);

if(isset($_POST['submit'])){
	$title = $_POST['title'];
	$content = $_POST['content'];
	$cat = $_POST['cat'];
	$image = $_FILES['image'] ['name'];
	$image_tmp = $_FILES['image'] ['tmp_name'];
	move_uploaded_file($img_tmp,"../images/$image");


	$query = "INSERT INTO posts (category_id,title,content,image) VALUES ('$cat',$title,'$content','$image')";
     $run = $db->insert($query);
}

     ?>




<!DOCTYPE html>
<html>
<head>
	<title>Insert Post</title>
</head>
<body>

<form action="insert.php" method="post" enctype="multipart/form-data">
<center><table width="800" align="center" border="2"></center>
<tr bgcolor="orange">
<td colspan="6"><h1 style="text-align:center">Insert new Post:</h1></td>
</tr>

<tr>
	<td align="right" bgcolor="orange">Post title</td>
	<td><input type="text" name="title" size="60"></td>
</tr>
<tr>
	<td align="right" bgcolor="orange">Post Category</td>
	<td>

		<select name="cat">
		 <option >Select a Category</option>
		 <?php while($row1 = $cats->fetch_array()) :?>
		 	<option value="<?php echo $row['id'];?>"><?php echo $row1 ['title'];?></option>
		<?php endwhile ;?>
		</select>
	</td>

</tr>



<tr>
	<td align="right" bgcolor="orange">Post image</td>
	<td><input type="file" name="image" size="50"></td>
</tr>
<tr>
	<td align="right" bgcolor="orange">Post Content</td>
	<td><textarea name="content" rows="15" cols="40"></textarea></td>
</tr>
<tr>
	
	<td colspan="6" align="center" bgcolor="orange"><input type="Submit" name="Submit" value="Publish now"/></td>
</tr>

</body>
</html>

推荐答案

db = new database();
db = new database();


查询 = " ;
query = "SELECT * FROM categories";


猫 =
cats =


这篇关于无法将帖子插入数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆