我的留言板

[size=large][color=red]control中main.php文件:[/color]<?php session_start();
class Main extends Controller
{
function main()
{
parent::Controller();
$this->load->helper(array('url','date','form'));//要填多个就要有array.
$this->load->helper('email');
$this->load->database();
$this->output->enable_profiler(TRUE);
//$this->load->helper('date');


}
function index()
{
$this->load->view('talkingroom');
}

function test()
{
/*//用location跳转达到这个页面
$path = site_url().'/main/get';
echo "<script>location.href='$path'</script>"; */
}

function get()
{
if(isset($_POST['originator']))
{
if($_POST['originator'] == $_SESSION['code'])
{
// 处理表单数据
$time = $this->input->post('time');
$title = $this->input->post('title');
$name = $this->input->post('name');
$mail = $this->input->post('mail');
$content = $this->input->post('content');
//这里把input里东西都插入到数据库中了
$sql = "insert into mytable (title,mail,name,content,time) value('$title','$mail','$name','$content','$time')";
$this->db->query($sql);
}else{
echo '请不要刷新本页面或重复提交表单!';
}
}


//展示数据
$sql_out = "select * from mytable";
$query['info'] = $this->db->query($sql_out);
$this->load->view('talkingroom',$query);
}
}
?>


[color=red]view-> talkingroom.php:[/color]<?php
//根据当前SESSION生成随机数
$code = mt_rand(0,1000000);
$_SESSION['code'] = $code;
$datestring = "%Y 年 %m 月 %d 日 - %h:%i %a";
$time = now();
$thistime = mdate($datestring, $time);
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>留言板</title>
<link rel="stylesheet" type="text/css" href="<?=base_url() ?>scripts/talk.css" >
<script type="text/javascript" src="<?=base_url() ?>scripts/control.js" ></script>

<!-- 在这里检验表单里的数据是否符合要求 -->
<script type="text/javascript">
function checkForm(){
var title = document.myform.title.value;
var content = document.myform.content.value;
var mail = document.myform.mail.value;
if(title=="")
{
alert('标题不能为空!');
document.myform.title.focus();
return false;
}else if(content=="")
{
alert("内容不能为空!");
document.myform.content.focus();
return false;
}else if(!mail=="")
{
var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
chkFlag = pattern.test(mail);
if(chkFlag){
return true;
}
else
{
alert("邮箱地址的格式不正确或为空!");
document.myform.mail.focus();
return false;
}
}
else
return true
}

</script>
</head>
<body>

<!-- 这是发表了的留言展示表: -->
<?php
if($info->num_rows()>0):
$s=1;
foreach($info->result() as $row):
?>
<table width="744" height="194px" border="1" cellspacing="0" align="center" bordercolor="#999999" >
<tr>
<td width="145" height="36"><?=$s?>楼</td>
<td width="302">标题:<?=$row->title?></td>
<td width="291">      <img src="<?=base_url() ?>image\f\email.gif"> <img src="<?=base_url() ?>image\f\reply.gif"> </td>
</tr>
<tr>
<td colspan="3">
<div>
<table width="752" height="151px" border="0" cellspacing="0">
<tr>
<td width="346" height="38">【作者】<?=$row->name?></td>
<td width="380">【发表时间】<?=$row->time?></td>
</tr>
<tr>
<td height="34" colspan="2">【留言内容】<?=$row->content?></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<p></p>
<?php $s++;
endforeach;
endif;
?>


<!-- 这是将要发表的留言: -->
<form name="myform" action="<?=site_url()?>/main/get" method="post" οnsubmit="return checkForm()"><!-- site_url为http://localhost:4444/ci/index.php base_url为http://localhost:4444/ci-->
<input type="hidden" name="originator" value="<?=$code?>">
<INPUT TYPE="hidden" NAME="time" value="<?=$thistime ?>">
<table width="497" align="center" cellspacing="0" class="menu" border="1" bordercolorlight="#CCCCCC" >

<tr>
<td height="30" colspan="2"><strong>发表留言</strong></td>
</tr>
<tr class="item" >
<td width="120">标题
<br>
title:</td>
<td width="389" ><input width="300px" type="text" name="title"><a class="a">*<a></td>
</tr>
<tr>
<td>姓名<br>
name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>邮件<br>
mail:</td>
<td><input type="text" name="mail"></td>
</tr>
<tr>
<td height="120">留言内容<br>
the content
of message </td>
<td><textarea name="content" rows="5" cols="60" ></textarea><br/><a class="a">*<a></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="提交" >
<input name="reset" type="reset" id="reset" value="重设"></td>
</tr>
</table>
</form>

</body>
</html>[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值