连接数据库的问题 [英] Issues with connection to database

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

问题描述

美好的一天!我是PHP学习者的新闻。这里我遇到了与数据库连接的问题。请帮我解决。我一直在尝试将HTML模板连接到我的数据库。



我尝试过:



Good day! I am news PHP learner.Here I've got issues with connection to database.Please help me to solve it. I've been trying to connect HTML template to my database.

What I have tried:

<pre>
<html>
<head>
	<title>Insert new post</title>
</head>


<body>
<form method="center" action="insert_post.php" enctype="multipart/form-data">
<table width="600" align="center" border="10">
<tr>
	<td align="center" bgcolor="yellow" colspan="6" ><h1>Inset new post here</h1></td>
</tr>
<tr>
	<td align="center">Post title</td>
	<td ><input type="text" name="title" size="30"></td>
</tr>
<tr>
	<td align="center">Post keywords</td>
	<td ><input type="text" name="title" size="30"></td>
</tr>
<tr>
	<td align="center">Post content</td>
	<td ><textarea name="content" cols="60" rows="15"></textarea></td>
</tr>
<tr>
	<td align="center" colspan="6"><input type="submit" name="submit" value="Publish now"></td>
 
</tr>
</table>
</form>


</body>
</html>

<?php
$db = mysqli_connect('localhost','root','','template');


if(isset($_POST['submit'])){
echo $post_title=$_POST['title'];
 echo $post_keywords=$_POST['keywords'];
echo $post_content=$_POST['content'];


if($post_title=='' or $post_keywords=='' or $post_content==''){ 
	
		echo "<script>alert('any of the fields is empty')</script>";


exit();

}
else{
$insert_query="INSERT INTO posts(post_title,post_keywords,post_content) values('$post_title','$post_keywords','$post_content')";

if(mysqli_master_query($insert_query)){

		echo"<center><h1>POST PUBLISHED succesfully</h1></center>";
}

}


}
?>

推荐答案

db = mysqli_connect(' localhost' root'' '' 模板');


if(isset(
db = mysqli_connect('localhost','root','','template'); if(isset(


_POST [' submit'])){
echo
_POST['submit'])){ echo


post_title =
post_title=


这篇关于连接数据库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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