1.链接数据库通用方法:conn.php 
<?php 
//第一步:链接数据库 
$conn=@mysql_connect("localhost:3306","root","root")or die ("mysql链接失败"); 
//第二步: 选择指定的数据库,设置字符集 
@mysql_select_db("php_blog",$conn) or die ("db链接失败".mysql_error()); 
mysql_query('SET NAMES UTF8')or die ("字符集设置错误"); 
?> 

2.查询判断 select.php 
<?php 
include("conn.php");//引入链接数据库<pre name="code" class="html"><?php 
include("conn.php");//引入链接数据库 
if(!empty ($_GET['id'])){ 
$sql="select * from news where id='".$_GET['id']."'"; 
$query=mysql_query($sql); 
$rs=mysql_fetch_array($query); 
//判断$rs有值说明数据库存在,否则数据库不存在;
} 
?> 
<form action="add.php" method="post"> 
标题: <input type="text" name="title"><br> 
内容: <textarea rows="5" cols="50" name="con"></textarea><br> 
<input type="submit" name="sub" value="发表"> 
</form> 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
猜你喜欢
  • 2021-05-26
  • 2022-12-23
  • 2023-03-20
  • 2022-12-23
  • 2021-07-23
  • 2021-09-08
相关资源
相似解决方案