PHP+Mysql留言板不显示内容!! 25
conn.php$link=mysqli_connect("localhost","root","")ordie(数据库链接错误);mysqli_select_db($l...
conn.php$link = mysqli_connect("localhost","root","") or die(数据库链接错误); mysqli_select_db ($link,"liuyan"); mysqli_query($link,"set names utf8");doAdd.php <?php include("manu.php");?> <?php include_once("conn.php");?> <h3>添加留言</h3> <?php //留言添加步骤 $title=$_POST["title"]; //1,获取添加的留言信息,并且补上其他辅助信息 if( $title != ""){ //留言标题 $author=$_POST["author"];//留言者 $content=$_POST["content"];//留言内容 $ip=$_SERVER['REMOTE_ADDR'];//留言地址 $addtime= date("Y-m-d h:i:s");//留言时间 $link =@ mysqli_connect("localhost","root","") ; if( $link) echo "ok!<br>"; else { echo "bad!<br>"; } mysqli_select_db($link,"liuyan");//选择数据 $sql="insert into table1(title,author,content,ip,addtime)values('$title','$author','$content','$ip','$addtime')"; $res=mysqli_query($link,$sql); mysqli_close($link); } else mysqli_close($link); ?>show.php<?php include("manu.php");?> <?php include_once("conn.php");?> <h3>查看留言</h3> <table width="700" border="1" > <tr> <th>标题</th> <th>留言者</th> <th>留言内容</th> <th>留言id</th> <th>留言时间</th> <th>操作</th> </tr><?php $sqlstr = "select * from table1 order by id"; $link = mysqli_connect("localhost","root",""); //$info=mysqli_query($link,"select * from table1 order by id"); 结果集 $result = mysqli_query($link,$sqlstr); if (!$result) { printf("Error: %s\n", mysqli_error($link)); exit();} while ($rows = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td align='left'>$list[title]</td>"; echo "<td align='left'>$list[author]</td>"; echo "<td align='left'>$list[content]</td>"; echo "<td>".date("Y-m-d H:i:s",$list[addtime]+8*3600)."</td>"; echo "<td align='left'>$list[ip]</td>"; echo "<td><a href='del.php?id={$list[id]}'>删除</a></td>"; echo "</tr>"; } mysqli_close($link) ;?>index.php<?php include("manu.php");?> <?php include("conn.php");?> <h3>添加留言</h3> <form action=" doAdd.php " method="post"> <table width="380" border="0" cellpadding="4"> <tr> <td align="right" >标题:</td> <td><input type="text" name="title" /></td> </tr> <tr> <td align="right">留言者:</td> <td><input type="text" name="author" /></td> </tr> <tr> <td align="right" valign="top">留言内容:</td> <td><textarea name="content" rows="5" cols="30"></textarea></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="提交" /> <input type="reset" value="重置" /> </td> </tr> </table> </form>
展开
2个回答
2018-06-12 · 知道合伙人软件行家
关注
展开全部
你没有选择数据库
$res = mysqli_select_db($this->link_id,'你的数据库名称');
if(!$res){echo '数据库选择失败';die;}
mysqli_set_charset($this->link_id,'utf8');
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询