如何将项目发送到数据库? [英] How do I send my project to database?
本文介绍了如何将项目发送到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我做的一切都很好!但是我的insert_post无法发送到我的数据库!
我尝试过:
<!DOCTYPE html>
< html >
< head >
< title > 插入新帖子< / title >
< / head >
< body >
< form 方法 = POST action = insert_post.php enctype = multipart / form-data >
< table width = 600 < span class =code-attribute> align = center border = 10 >
< tr >
< td align = center bgcolor = 黄色 < span class =code-attribute> colspan = 6 > < h1 > 在此处插入新帖子< / h1 > < / td >
< / tr >
< tr >
< td align = right > 帖子标题< / td >
< td > < input type = text name = title < span class =code-attribute> size = 30 > < / td >
< / tr >
< tr >
< td align =跨度> right > 作者< / td >
< td > < 输入 type = text name = 作者 size = 30 > < / td >
< / tr >
< tr >
< td align = 正确 > 发布关键字< / td >
< td > < 输入 type =温泉n> text name = 关键字 大小 = 30 > < / td >
< / tr >
< tr >
< td align = right< /跨度> <跨度class =code-keyword>> 发布图片< / td >
< td < span class =code-keyword>> < input 类型 = file name = image > < / td >
< / tr >
< span class =code-keyword>< tr >
< td align = right > 发布内容< / td >
< td > < textarea 名称 = content cols = 30 行 = 15 > < / textarea > < / td >
< / tr >
< tr >
< td align = center colspan = 6 > < 输入 < span class =code-attribute> type = submit name = 提交 value = 立即发布 > < span class =code-keyword>< / td >
< / tr >
< / form >
< / body >
< / html >
<? php
$ db = mysqli_connect(< span class =code-string> localhost, root, , student);
// mysqli_select_db(student);
if(isset($ _ POST [' submit'])){
$ post_title = $ _ POST [' title'];
$ post_date = date(' d-m-y');
$ post_author = $ _POST [' 作者跨度>];
$ post_keywords = $ _ POST [' keywords'];
$ post_content = $ _ POST [' content'];
$ post_image = $ _ FILES [' image'] [' name'];
$ image_tmp = $ _FILES [' image'] [' tmp_name'];
move_uploaded_file($ image_tmp, ../ images / $ post_image跨度>);
$ insert_query = INSERT到posta(post_title,post_date,post_author,post_image,post_keywords, post_content)
values('$ post_title','$ post_date','$ post_author','$ post_image','$ post_keywords','$ post_content');
if(mysqli_query($ db,$ insert_query)){
echo < center>< h1>发布成功发布!< / h1>< / center>;
}
}
?> ;
解决方案
db = mysqli_connect( localhost, root, , 学生跨度>);
// mysqli_select_db(student);
if(isset(
_POST [' submit 跨度>])){
POST_TITLE =
I think I did everything fine!But my insert_post cant be sent to my database!
What I have tried:
<!DOCTYPE html>
<html>
<head>
<title>Inserting new posts</title>
</head>
<body>
<form method="POST" action="insert_post.php" enctype="multipart/form-data">
<table width="600" align="center" border="10">
<tr>
<td align="center" bgcolor="yellow" colspan="6"><h1>Insert new post here</h1></td>
</tr>
<tr>
<td align="right">Post Title</td>
<td><input type="text" name="title" size="30"></td>
</tr>
<tr>
<td align="right">Author</td>
<td><input type="text" name="author" size="30"></td>
</tr>
<tr>
<td align="right">Post Keywords</td>
<td><input type="text" name="keywords" size="30"></td>
</tr>
<tr>
<td align="right">Post image</td>
<td><input type="file" name="image" ></td>
</tr>
<tr>
<td align="right">Post Content</td>
<td><textarea name="content" cols="30" rows="15"></textarea></td>
</tr>
<tr>
<td align="center" colspan="6"><input type="submit" name="submit" value="Publish now"></td>
</tr>
</form>
</body>
</html>
<?php
$db= mysqli_connect("localhost","root","","student");
// mysqli_select_db("student");
if(isset($_POST['submit'])){
$post_title=$_POST['title'];
$post_date=date('d-m-y');
$post_author = $_POST['author'];
$post_keywords=$_POST['keywords'];
$post_content=$_POST['content'];
$post_image=$_FILES['image']['name'];
$image_tmp= $_FILES['image']['tmp_name'];
move_uploaded_file($image_tmp, "../images/$post_image");
$insert_query="INSERT into posta (post_title, post_date, post_author, post_image,post_keywords, post_content)
values ('$post_title','$post_date','$post_author','$post_image','$post_keywords','$post_content')";
if(mysqli_query($db, $insert_query)){
echo "<center><h1>Post Published succesfully!</h1></center>";
}
}
?>
解决方案
db= mysqli_connect("localhost","root","","student"); // mysqli_select_db("student"); if(isset(
_POST['submit'])){
post_title=
这篇关于如何将项目发送到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文