PHP毕业设计——许愿墙(有源码)

许愿

在这里插入图片描述

许愿成功

在这里插入图片描述

项目结构

│  add.php 
│  connect.php
│  delete.php
│  index.php
│  README.md
│  wish.php
│  wish.sql
├─Css 
├─Images
└─Js

添加记录

<?php
include_once("./connect.php");

//验证码后台校验
$code=$_POST["code"];
$recode=$_POST["recode"];

if ($code!=$recode) {
	  echo"<script>alert('验证码错误');history.go(-1);</script>";  
}
//获取必要的数据库文件
$name=$_POST["name"];
$name=htmlspecialchars($name);
$time=time();
$color=$_POST['idvalue'];
$content=$_POST["content"];
$content=htmlspecialchars($content);


//进行数据的插入
$sql = "INSERT INTO wall(name, time, color,content) VALUES ('".$name."',$time,'".$color."','".$content."')";
$result = mysqli_query($conn,$sql);

//echo mysqli_error($conn);

if ($result) {
	echo "Success";

	header("Location: ./index.php"); 


}


?>

连接数据库

<?php

//1、连接数据库
// $link = @mysql_connect('localhost','root','') or die('数据库连接失败!');
// //2、选择数据库
// mysql_select_db('wish') or die('选择的数据库不存在!');
// //3、设置字符集
// mysql_set_charset('utf8');
$conn = mysqli_connect('localhost','root','root','wall');
mysqli_query($conn,'set names utf8');




删除数据

<?php
include_once("./connect.php");

$id=$_GET['id'];

$sql = "DELETE FROM wall where id=$id";

$result = mysqli_query($conn,$sql);

if ($result) {
	echo "Success";

	header("Location: ./index.php"); 

}

?>

读取数据


<?php
include_once("./connect.php");
//获取所有数据
$sql = 'SELECT * FROM wall';
$result = mysqli_query($conn,$sql);
$data = mysqli_fetch_all($result,MYSQLI_ASSOC);




?>

<!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" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>许愿墙</title>
	<link rel="stylesheet" href="./Css/index.css" />
	<script type="text/javascript" src='./Js/jquery-1.7.2.min.js'></script>
	<script type="text/javascript" src='./Js/index.js'></script>
</head>
<body>
	<div id='top'>
		<span id='send'></span>
	</div>
	<div id='main'>
	<?php foreach ($data as $v) { ?>
		<dl class='paper <?php echo $v['color']?>'>
			<dt>
				<span class='username'>	<?php echo $v['name']?>;</span>
				<span class='num'>No.	<?php echo $v['id']?></span>
			</dt>
			<dd class='content'>	<?php echo $v['content']?></dd>
			<dd class='bottom'>
				<span class='time'>	<?php $date=date('Y-m-d H:i:s',$v['time']);  echo $date?></span>
				<a href="./delete.php?id=<?php echo $v['id'] ?>" class='close'></a>
			</dd>
		</dl>
		<?php } ?>






		
	
	</div>
	
<!--[if IE 6]>
    <script type="text/javascript" src="./Js/iepng.js"></script>
    <script type="text/javascript">
        DD_belatedPNG.fix('#send,#close,.close','background');
    </script>
<![endif]-->
</body>
</html>

添加数据页面

<?php
include_once("./connect.php");

$sql = 'SELECT id FROM wall order by id desc limit 1';

$result = mysqli_query($conn,$sql);

//获得数据目录条数

$num = mysqli_fetch_all($result,MYSQLI_ASSOC);


$id = array_column($num, 'id');

$n=$id['0']+1;

echo "$n";
?>


<!DOCTYPE  >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>许愿墙</title>
	<link rel="stylesheet" href="./Css/index.css" />
	<script type="text/javascript" src='./Js/jquery-1.7.2.min.js'></script>
	<script type="text/javascript" src='./Js/index.js'></script>
	<style type="text/css">
		#content {
			width: 638px;
			height:650px;
			margin:0 auto;
			margin-top:100px;
			/*background-color:#F0FAFF;
			border:2px solid #C9F;*/
		}
		#content .c-top{
			width: 638px;
			height: 80px;
			background: url(./Images/content_top.jpg) no-repeat;
		}
		#content .c-bottom{
			width: 638px;
			height: 50px;
			background: url(./Images/content_bottom.jpg) no-repeat;
		}
		.c-content{
			width: 638px;
			height: 470px;
			background: url(./Images/content_bg.jpg) repeat;
		}
		.papercolor{
			width:588px;
			height: 60px;
			margin-left: 35px;
			padding-top:15px;
		}
		.p-left{
			float: left;
			width: 120px;
			line-height: 27px;
		}
		.p-right{
			float: left;			
		}
		.color330{
			float: left;
			margin-left: 20px;
			border-right: #404040 1px solid; 
			border-top: #404040 1px solid;  
			border-left:#404040 1px solid;
			width: 25px;
			cursor: pointer;
			border-bottom: #404040 1px solid;
			height: 25px;
		}
		.papercontent{
			width: 588px;
			height: 210px;
			margin-left: 35px;
		}
		.left{
			width: 294px;
			height:100px;
			float: left;
		}
		.right{
			width: 294px;
			height:100px;
			float: left;
		}
		.left-top{
			margin-bottom: 10px;
		}
		.left-bottom{

		}
		.right-top{
			margin-bottom: 10px;
		}
		.right-bottom{
			width:200px;
			height:150px;
			border: 1px solid orange;
			margin-left:20px;
			background-color:#E8DEFF;
		}
		.name{
			clear: both;
			width: 588px;
			height: 50px;
			margin-left: 35px;
			margin-top:10px;
		}
		.name-left{
			width:60px;
			height: 26px;
			line-height: 26px;
			float: left;
		}
		.name-right{
			float: left;
		}
		.name-right input{
			width: 200px;
			height: 26px;
		}
		.code{
			clear: both;
			width: 588px;
			height: 50px;
			margin-left: 35px;
			margin-top:10px;
		}
		.code-left{
			width:50px;
			height: 26px;
			line-height: 26px;
			float: left;
		}
		.code-content{
			width:100px;
			float: left;
		}
		.code-content input{
			width: 100px;
			height: 26px;
		}
		.code-right{
			float:left;
			margin-left: 10px;
		}
		.code-right input{
			width: 40px;
			height: 26px;
			background-color: pink;
		}
		.submit{
			width:174px;
			height:38px;
			background: url(./Images/pic_submit.gif) no-repeat;
			margin-left:217px;
		}
		.shuname{
			width:80px;
			height:25px;
			margin-left: 120px;
		}
		span{
			font-size: 13px;
			font-family: "微软雅黑";
		}
	</style>
	
</head>
<body>
	<div id='top'></div>
	<div id="content">
		<div class="c-top"></div>
		<form action="add.php" method="post" id="myfrom">
			<div class="c-content">
				<div class="papercolor">
					<div class="p-left">
						<span>请选择纸条颜色:</span>
					</div>
					<div class="p-right">
						<div class="color330" id="a1" style="background:#FFDFFF"></div>
	                  	<div class="color330" id="a2" style="background:#C3FEC0"></div>
	                  	<div class="color330" id="a3" style="background:#FFE3b8"></div>
	                  	<div class="color330" id="a4" style="background:#CEECFF"></div>
	                 	<div class="color330" id="a5" style="background:#E8DEFF"></div>
	                 	<input type="hidden" value="" name="idvalue" id="idvalue">	             	
					</div>
				</div>
				<div class="papercontent">
					<div class="left">
						<div class="left-top">
							<span>输入你的祝福纸条内容:</span>
						</div>
						<div class="left-bottom">
							<textarea cols="25" rows="8" name="content" id="textfont"></textarea>
						</div>
					</div>
					<div class="right">
						<div class="right-top">
							<span>纸条效果预览:</span>
						</div>
						<div class="right-bottom">
							<div style="height:15px"><span><?php echo $n ?></span><br/></div>
						 	<div style="height:100px;margin-top:10px"><span id="font"></span></div>
						 	<div class="shuname"><span id="name">署名:</span></div>			
						</div>
					</div>
				</div>
				<div class="name">
					<div class="name-left">
						<span>您的署名:</span>
					</div>
					<div class="name-right">
						<input id="nameright" type="text" name="name" value="">
					</div>
				</div>
				<div class="code">
					<div class="code-left">
						<span>验证码:</span>
					</div>
					<div class="code-content">
						<input id="codeone" type="text" name="recode" value=""><span></span>
					</div>
					<div class="code-right">
						<input id="codetwo" type="text" name="code" value="<?php echo mt_rand(1000,9999); ?>" readonly>
					</div>				
				</div>
				<!--<div class="submit"><button type="submit" style="width:174px;height:38px"></button></div>-->
				<input style="BORDER-RIGHT: #f33b78 1px outset; BORDER-TOP: #f33b78 1px outset; FONT-WEIGHT: bold; BORDER-LEFT: #f33b78 1px outset; COLOR: #ffffff; BORDER-BOTTOM: #f33b78 1px outset; BACKGROUND-COLOR: #70ae0b;margin-left: 225px" type="submit" value="→ 开始贴许愿小纸条 ←" name="submit">
				
	                <input class="input" type="button" name="Submit2" value="返回">	
			</div>
		</form>
		<hr/ style="color:orange;width:550">
		<div class="c-bottom"></div>
	</div>
<!--[if IE 6]>
    <script type="text/javascript" src="./Js/iepng.js"></script>
    <script type="text/javascript">
        DD_belatedPNG.fix('#send,#close,.close','background');
    </script>
<![endif]-->
	<script type="text/javascript">
		//改变颜色
		$(".color330").click(function(){			
			var value=$(this).css("background-color");
			var idvalue=$(this).attr("id");
			console.log(idvalue);
			$("#idvalue").attr("value",idvalue);
			$(".right-bottom").css("background-color",value);
		})

		//改变值触发的事件
		var textfont = document.getElementById('textfont');
		var font = document.getElementById('font');
		textfont.onchange=function(){
			font.innerHTML=textfont.value;			
		}

		//改变值触发的事件
		var nameright = document.getElementById('nameright');
		nameright.onchange=function(){
			document.getElementById("name").innerText="署名: "+nameright.value;	
		}
		
		//在填写完毕验证码之后验证是否一致
		var codeone = document.getElementById('codeone');
		var codetwo = document.getElementById('codetwo');
		//表单时区焦点事件
		codeone.onblur=function(){
			//验证两次验证码是否一致
			if(codeone.value != codetwo.value){
				this.nextSibling.innerHTML='验证码不一致!'
				this.nextSibling.style.color='red';
			}
		}

		$( '.input' ).click( function () {
			window.location.href="index.php"; 
		} );
			
	</script>
</body>
</html>

源码
https://github.com/hiszm/WishWall

GitHub 网络不好的话 关注公众号 (扫一扫下方二维码)孙中明;回复 6002 获取代码

更新版本如下

https://hiszm.blog.csdn.net/article/details/121856149

  • 19
    点赞
  • 172
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 21
    评论
许愿墙是一个让人们可以在上面许下自己心愿的地方,也是一个可以分享和交流愿望的平台。在网页上展示许愿墙php代码可以通过以下步骤实现: 1. 首先,需要创建一个数据库来存储用户的心愿。可以使用MySQL等数据库管理系统来创建一个名为“wishing_wall”的数据库,里面包含一个名为“wishes”的表来存储心愿信息,包括心愿内容、发布时间等字段。 2. 在php代码中,需要连接到数据库并查询出用户的心愿信息。使用mysqli_connect()函数来连接到MySQL数据库,然后使用mysqli_query()函数来执行查询语句,从“wishes”表中获取心愿信息。 3. 将查询到的心愿信息在网页上进行展示。使用php的循环语句来遍历查询结果,将每一个心愿以特定的格式展示在网页上,比如使用ul和li标签来列表展示每一个心愿。 4. 在页面上提供一个输入框和提交按钮以便用户可以输入自己的心愿。使用php来处理用户提交的信息,将用户输入的心愿存储到数据库中,并在页面上刷新出新的心愿列表。 5. 最后,为许愿墙php页面添加一些样式和交互效果,比如使用CSS来美化页面样式,使用JavaScript来实现交互功能,比如点击按钮提交心愿等。 通过以上步骤,就可以实现一个简单的许愿墙php代码展示,让用户可以在网页上分享自己的心愿,也可以看到其他人的心愿,从而实现交流和分享的目的。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孙中明

喝杯咖啡????

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值