Ⅰ php+mysql留言板发布文章问题
我会再建一个用户表,用户表字段包括:id,username, age, grade(用户等级)。。。
然后在文章表中添加一个字段 uid 用来存发表文章的用户的id。
一个用户能够发表多篇文章,用关系型数据库mysql模拟就是这样。是一对多的关系。一个用户对应多篇文章。在文章表中保存用户id便可。
查询的时候连表查询(使用 join 关键字),便可,比如:
select i_title, i_content , username from articleTable as a join userTable as u on a.uid = u.id ;
其中的 userTable as u 是给表起别名,方便sql语句其他地方调用,不用写那么长的表名。
Ⅱ PHP APA MYSQL制作一个简单的留言板
不多说,直接给你贴地址:
http://www.codepub.com/software/view-software-15539.html
http://www.codedn.com/view/2359.html
这个网上很多,如果以上不满意,可以自己选择比较合适的:
http://www.google.cn/search?hl=zh-CN&client=pub-2918997108407961&prog=aff&newwindow=1&q=php%E7%95%99%E8%A8%80%E6%9C%AC+%E6%BA%90%E7%A0%81&btnG=Google+%E6%90%9C%E7%B4%A2&aq=f&oq=
留言本其实很简单,建议自己写一个,很容易。如果楼主是php爱好者,可以加入我们团。我们定期做一些技术专题。
Ⅲ 用php,mysql制作留言板
你的程序一开始就已经require deal.php了,不明白为什么form里面的action还是指向deal.php,把那个action='',自然就可以了。
Ⅳ php与mysql写留言板的原理
1.读库,取数据信息做显示列表(登录和非登录都可以看到)
2.登录发表,你留言板 数据库里面要有一个字段对应用户的id,暂称为user_id,A用户,发表了3条信息,你取数据的时候,跟上当前用户的user_id,当然 在用户登录后,你要生成用户cookie 或者session,这样才能得到当前是那个用户登录的。
Ⅳ PHP+mysql做一个留言板
先select 你的留言板 内容 送入数组 result
然后循环for($i=0;$i<count($result);$i++){$result[$i]['question_no'] = $i+1;} 然后前台调foreach循环的 question_no 只有思路 具体你要自己写
第二个问题 问错了 如果循环对的话 和 div 对应的话 不会出错的 你要自己检查你是否写对没
Ⅵ php+MySQL实现简单留言、修改、删除功能,遇到问题!
$sql = "DELETE FROM gbook WHERE id = '$id' ";
原因:1关了全局变量后,register_globals = Off 传递的参数在接收时就得用$_POST或者是$_GET或是$_REQUEST了
2依据你的情况,$sql = "DELETE FROM gbook WHERE id = '".$_GET['id']."'";
试试这样是否可以,另外,其实在接收参数的时候,在使用前最好做些安全过滤,不然不安全,不过,做为练习用,倒是无防,希望可以帮到你
Ⅶ PHP+mysql写一个留言板
在留言表单插入表单插入代码mysql:数据库的用户名是:root 密码:123456
:<?php
$conn=mysql_connect("localhost","登陆mysql数据库的用户名","登陆mysql数据库的密码");//建立数据库连接资源
if(!$conn) echo"数据库连接有误";//判断数据库连接是否有误
mysql_query("set names'gbk'");设置中文显示防止乱码出现
mysql_select_db('连接的数据库名
',$conn);//连接的数据库名
$sql="INSERT INTO `liuyan`.`use_info` (
`name` ,
`sex` ,
`text`
)
VALUES (
'$name', '$sex', '$text'
)";//想liuyan这数据库写入数据
mysql_query($sql);//让sql语句执行
mysql_close;//关闭连接节省机子内存
?>
让留言的内容在指定页面显示大体和上面的语句差不多:<?php $conn=mysql_connect('localhost','用户登陆数据库的用户名','登陆数据库的密码');
if(!$conn) echo '数据库连接有误';//判断数据库的连接是否有误
mysql_select_db('liuyan',$conn);//数据库的选择
mysql_query("SET NAMES 'GBK'");//设置数据库中文的显示
$sql="select * from use_info"; //要链接的目标数据库
$result=mysql_query($sql);//让sql语句执行
/*$rs=mysql_fetch_array($result) //将数据库的内容保存的数组变量中*/
while($rs=mysql_fetch_array($result))
{
echo $rs['name']."".$rs['sex']."".$rs['text'].""."</br>";
}//循环显示数组内容
mysql_close;//数据库的关闭
?>
Ⅷ php+mysql 一篇文章对应多个留言..怎么做
建2个表,
一个是文章表,数据结构为:
id,文章标题,文章内容,上传时间,上传人,留言数量。
一个是留言表,数据结构为:
id,文章id,留言标题 ,留言内容,留言时间,留言人。
两个表的id是自增的,是一个唯一的识别记录的标记,留言表中“文章id”则对应于文章表中“id”,这样通过“文章id”就可以关联到文章表的文章。
Ⅸ php怎么在mysql创建留言板步骤
工具:
Dreamweaver
php、mysql服务器
步骤/方法
首先是确定自己的留言板需求.例如:名字,邮件及留言内容.
一. 建立一个数据库guestbook。
CREATE TABLE IF NOT EXISTS `content` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(20) NOT NULL,
`email` varchar(50) NOT NULL,
`content` varchar(200) NOT NULL,
PRIMARY KEY (`id`))
ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3;
二. 新建config.php
< ? php
$q = mysql_connect("服务器","数据库用户","数据库密码");
if(!$q)
{
die('Could not connect: ' . mysql_error());
}
mysql_query("set names utf8"); //以utf8读取数据
mysql_select_db("guestbook",$q); //数据库
?>
三. 新建index.php
< ?php
include("config.php"); //引入数据库连接文件
$sql = "select * from content"; //搜索数据表content
$resule = mysql_query($sql,$q);
?>
< html>
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< body>
< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首页< /a> | < a href="liuyan.php">留言< /a>< /td>
< /tr>
< /table>
< p>
< ?
while($row=mysql_fetch_array($resule))
{
?>
< /p>
< table width="678" border="1" align="center" cellpadding="1" cellspacing="1">
< tr>
< td width="178">Name:< ? echo $row[1] ?>< /td>
< td width="223">Email:< ? echo $row[2] ?>< /td>
< /tr>
< tr>
< td colspan="4">< ? echo $row[3] ?>< /td>
< /tr>
< tr>
< /table>
< ?
}
?>
< /body>
< /html>
四. 新建liuyan.php
< html>
< body>
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首页< /a> | < a href="liuyan.php">留言< /a>< /td>
< /tr>
< /table>
< table align="center" width="678">
< tr>
< td>
< form name="form1" method="post" action="post.php">
< p>
Name:
< input name="name" type="text" id="name">
< /p>
< p>Email:< input type="test" name="email" id="email">< /p>
< p>
留言:
< /p>
< p>
< textarea name="content" id="content" cols="45" rows="5">< /textarea>
< /p>
< p>
< input type="submit" name="button" id="button" value="提交">
< input type="reset" name="button2" id="button2" value="重置">
< /p>
< /form>
< /td>
< /tr>
< /table>
< /body>
< /html>
五. 新建post.php
< ?php
header("content-Type: text/html; charset=utf-8");
include("config.php");
$name= $_POST['name'];
$email= $_POST['email'];
$patch = $_POST['content'];
$content = str_replace("
","< br />",$patch);
$sql = "insert into content (name,email,content) values ('$name','$email','$content')";
mysql_query($sql);
echo "< script>alert('提交成功!返回首页。');location.href='index.php';< /script>";
?>
这样已经成功的写出一个留言板了。
第二部分
此次将在上面版本上加多管理,回复等功能。
首先在sql中字节。
ALTER TABLE `content` ADD `reply` VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `content`
一. 新建login.php
< html xmlns="http://www.w3.org/1999/xhtml">
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< title>无标题文档< /title>
< /head>
< body>< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首页< /a> | < a href="liuyan.php">留言< /a>< /td>
< /tr>
< /table>
< table align="center" width="678">
< tr>
< td align="center">
< form name="form1" method="post" action="login2.php">
< label for="textfield">< /label>
< p> < /p>
< p>帐号:
< input type="text" name="name" id="name">
< /p>
< p>密码:
< input type="password" name="pw" id="pw">
< /p>
< p>
< input type="submit" name="button" id="button" value="提交">
< input type="reset" name="button2" id="button2" value="重置">
< /p>
< /form>< /td>
< /tr>
< /table>
< /body>
< /html>
二.login2.php
< ?
session_start();
header("content-Type: text/html; charset=utf-8");
$name = $_POST['name'];
$pw = $_POST['pw'];
if($name == "admin" && $pw == "admin"){
$_SESSION["adminname"] = $name;
echo "< script>alert('登录完成,返回首页!');location.href='index.php';< /script>";
}else{
echo "< script>alert('错误!');location.href='login.php';< /script>";
}
?>
三. 在原有的index.php上添加
< ?php
session_start();
include("config.php");
$sql = "select * from content";
$resule = mysql_query($sql,$q);
?>
< html>
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< body>
< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首页< /a> | < a href="liuyan.php">留言< /a>< /td>
< td width="80">
// 新增管理员登录
< ?php
if (isset($_SESSION['adminname']) && $_SESSION["adminname"] == "admin"){
echo "< a href='logout.php'>登出< /a>";
}else{
echo "< a href='login.php'>管理员登录< /a>";
}
?>
< /td>
< /tr>
< /table>
< p>
< ?
while($row=mysql_fetch_array($resule))
{
?>
< /p>
< table width="678" border="1" align="center" cellpadding="1" cellspacing="1">
< tr>
< td width="178">Name:< ? echo $row[1] ?>< /td>
< td width="223">Email:< ? echo $row[2] ?>< /td>
< td width="100">
< ?php
if(isset($_SESSION['adminname']) && $_SESSION["adminname"] == "admin"){
echo "< a href='huifu.php?id=" . $row[0] . "'>回复< /a>";
echo " | " . "< a href='delete.php?id=" . $row[0] . "'>删除< /a>";
} else {
echo "";
}
?>
< /td>
< /tr>
< tr>
< td colspan="4">< ? echo $row[3] ?>< /td>
< /tr>
< tr>
< td colspan="4">< ?
if($row[4] == ""){
?>
< ? echo "暂无回复。";?>
< ? }else {echo "管理员回复:". $row[4]; } ?>< /td>
< /tr>
< /table>
< ?
}
?>
< /body>
< /html>
四. 新建huifu.php
< ?php
include("config.php");
$sql = "select * from content where id=".$_GET["id"];
$resule = mysql_query($sql,$q);
SetCookie("id",$_GET["id"]);
session_start();
header("content-Type: text/html; charset=utf-8");
if(empty($_SESSION["adminname"])){
exit("< script language='javascript'>alert('您尚未登录后台,或登录已超时,请重新登录!');window.location.href='login.php';< /script>");
}
?>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns="http://www.w3.org/1999/xhtml">
< head>
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< title>无标题文档< /title>
< /head>
< body>
< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首页< /a> | < a href="liuyan.php">留言< /a>< /td>
< /tr>
< /table>
< table align="center" width="678">
< tr>
< td>
< form name="reply" method="post" action="reply.php" >
< p>回复:
< ?
while($row=mysql_fetch_array($resule))
{
echo $row[3];
}
?>
< /p>
< p>
< textarea name="reply" id="reply" cols="45" rows="5">< /textarea>
< /p>
< p>
< input type="submit" name="button" id="button" value="回复" />
< input type="reset" name="button2" id="button2" value="重置" />
< /p>
< /form>
< /td>
< /tr>
< /table>
< /body>
< /html>
五. reply.php 回复留言提交页面.
< ?
include("config.php");
$id = $_COOKIE["id"];
$sql = "select * from content";
header("content-Type: text/html; charset=utf-8");
$patch = $_POST["reply"];
$reply = str_replace("
","< br />",$patch);
$resule = mysql_query("UPDATE `2`.`content` SET `reply` = '$reply' WHERE `content`.`id` ="."$id");
echo "< script>alert('回复成功!');location.href='index.php';< /script>";
?>
这样就可以建立出一个简单的管理.管理帐号都是admin 因为只是判别输入的是不是admin 是的话就把值输入进session中.