註冊,登入,增刪改查
阿新 • • 發佈:2021-06-15
1...註冊頁面
<form action="zhu.php"method="post"enctype="multipart/form-data">
<p>
手機號
<input type="tel" name="tel"required>
</p>
<p>
註冊姓名
<input type="tel" name="name"required>
</p>
<p>
密碼
<input type="password"name="password"required>
</p>
<p>性別
<input type="radio"name="sex"value="1"checked>男
<input type="radio"name="sex" value="2">女
</p>
<p>
註冊時間
<input type="date"name="data"required>
</p>
<p>
驗證碼
<input type="text"name="code">
<?php
$str='qewrty13245';
$strr='';
for ($i=0;$i<=4;$i++){
$k=rand(0,strlen($str)-1);
$code.=$str[$k];
}
echo $code;
setcookie('code',$code,time()+3600*24*7);
?>
<a href="">點選重新整理</a>
</p>
<p><input type="submit" value="立即註冊"></p>
</form>
2....登入頁面
<?php
/**
* Created by PhpStorm.
* User: Lenovo
* Date: 2021/6/5
* Time: 14:44
*/
//接受前端的值、
$unname=$_POST['name'];
$unpwd=$_POST['password'];
$code=$_POST['code'];
if (empty($unname)){
die('賬號不可以為空');
}
if (empty($unpwd)){
die('密碼不可以為空');
}
if (empty($code)){
die('驗證碼不可以為空');
}
//驗證驗證碼是否一致
if ($code!=$_COOKIE['code']){
die('兩次驗證碼輸入不一致');
}
//登入的查詢
$link=mysqli_connect('127.0.0.1','root','root','day4');
mysqli_set_charset($link,'utf8');
$sql="select * from zhu where phone='$unname' or name='$unname' ";
$result=mysqli_query($link,$sql);
$info=mysqli_fetch_assoc($result);
if (!$info){
die('賬號不存在');
}
if ($info['password']!=md5($unpwd)){
die('兩次密碼輸入不一致');
}
setcookie('phone',$info['phone']);
echo '登入成功';
header('refresh:3,url=zhan2.php');
die();
2......展示註冊頁面
<?php
//展示個人註冊頁面
/**
* Created by PhpStorm.
* User: Lenovo
* Date: 2021/6/5
* Time: 15:14
*/
//驗證票據
$cookie=$_COOKIE['phone'];
if (!$cookie){
echo '你還沒有登入';
header('refresh:3,url=deng.php');
die();
}
//根據登入給的cookIE存的書記查詢資訊
$link=mysqli_connect('127.0.0.1','root','root','day4');
mysqli_set_charset($link,'utf8');
$sql="select * from zhu where phone='$cookie'";
$result=mysqli_query($link,$sql);
$info=mysqli_fetch_assoc($result);
//print_r($info);
//進行展示,利用table或者ul進行展示
?>
<link rel="stylesheet" href="bootstrap.min.css">
<table class="table">
<tr>
<td>序號</td>
<td>手機號</td>
<td>姓名</td>
<td>密碼</td>
<td>性別</td>
<td>註冊時間</td>
</tr>
<?php
?>
<tr>
<td><?php echo $key+1 ?></td>
<td><?php echo $info['phone']?></td>
<td><?php echo $info['name']?></td>
<td><?php echo $info['password']?></td>
<td><?php echo $info['sex']?></td>
<td><?php echo $info['time']?></td>
</tr>
</table>
<?php
header('refresh:3,url=zhan3.php')
?>
3.....展示
<?php
//展示注資料庫全部資訊
/**
* Created by PhpStorm.
* User: Lenovo
* Date: 2021/6/5
* Time: 15:14
*/
?>
<?php
//接受搜尋的關鍵字
$word=$_GET['word'];
////接受搜尋的關鍵字
//分頁展示
//1找當前頁
$page=isset($_GET['page'])?($_GET['page']):1;
//2設定一頁幾條資料
$length=4;
//3,總共有幾條資料
$link=mysqli_connect('127.0.0.1','root','root','day4');
mysqli_set_charset($link,'utf8');
if (empty($word)){
$sql="select * from zhu";
}else{
$sql="select * from zhu where phone like '%$word%'";
}
$result=mysqli_query($link,$sql);
$count=mysqli_num_rows($result);
//4可以分幾頁
$last_page=ceil($count/$length);
//5計算偏移量
$limit=($page-1)*$length;
//6查詢以上資訊,進行sql語句拼寫
$sql="select * from zhu where phone like '%$word%'limit $limit,$length";
$result=mysqli_query($link,$sql);
$data=mysqli_fetch_all($result,1);
if ($word){
foreach ($data as $k=>$v){
$data[$k]['phone']=str_replace($word,"<font color='red'>$word</font>",$v['phone']);
}
}
?>
<form>
<input type="search"placeholder="請輸入手機好進行查詢" name="word">
<input type="submit" value="立即查詢">
</form>
<link rel="stylesheet" href="bootstrap.min.css">
<table class="table">
<tr >
<td>序號</td>
<td>手機號</td>
<td>姓名</td>
<td>密碼</td>
<td>性別</td>
<td>註冊時間</td>
<td>操作</td>
</tr>
<!-- 利用foreash展示資料庫資訊 -->
<?php
foreach ($data as $key=>$value){
?>
<tr>
<td><?php echo $value['id'] ?></td>
<td><?php echo $value['phone']?></td>
<td><?php echo $value['name']?></td>
<td><?php echo $value['password']?></td>
<td><?php echo $value['sex']?></td>
<td><?php echo $value['time']?></td>
<td><a href="shan.php?id=<?php echo $value['id'];?>&page=<?php echo $page;?>" onclick="if (confirm('你確定要刪除嗎?')){
return true
}else {return false}">刪除</a>
<a href="bian.php?id=<?php echo $value['id'];?>">編輯</a></td>
</tr>
<?php
}
?>
</table>
<?php
$prev=$page-1<=1? 1:$page-1;
$next=$page+1>=$last_page?$last_page:$page+1;
echo "<a href='?page=$prev&word=$word'>".'上一頁'."</a> "; // 上一頁
echo "<a href='?page=1?&word=$word'>".'首頁'."</a> "; // 第一頁
for ($i=1; $i<=$last_page; $i++) {
echo "<a href='?page=".$i."'>".$i."</a> ";
};
echo "<a href='?page=$last_page&word=$word'>".'尾頁'."</a> "; // 最後一頁
echo "<a href='?page=$next&word=$word'>".'下一頁'."</a>"; // 下一頁
?>
4.....刪除
<?php
/**
* Created by PhpStorm.
* User: Lenovo
* Date: 2021/6/5
* Time: 17:40
*/
;
//傳入當前頁進行接受,要不刪除當前頁條就回跳回第一頁
$del=$_GET['id'];
$page=$_GET['page'];
if (empty($del)){
die('id不可以為空');
}
if (!is_numeric($del)){
die('id不合法');
}
$link=mysqli_connect('127.0.0.1','root','root','day4');
mysqli_set_charset($link,'utf8');
//拼寫sql語句
$sql="delete from zhu where id=$del";
$result=mysqli_query($link,$sql);
if (!$result){
echo '刪除失敗';
header('refresh:3,url=zhan3.php?pag='.$page);
die();
}else{
echo '刪除成功';
header('refresh:3,url=zhan3.php?pag='.$page);
die();
}
5......修改
<?php
/**
* Created by PhpStorm.
* User: Lenovo
* Date: 2021/6/5
* Time: 19:26
*/
$id=$_POST['id'];
//1接值
$phone=$_POST['tel'];//手機號
$name=$_POST['name'];//姓名
$password=$_POST['password'];//密碼
$sex=$_POST['sex'];//性別
$time=$_POST['data'];//時間
//2,進行非空驗證
if (empty($phone)){
die('手機號不可以為空');
}
echo "<br>";
//$time=time();
//echo $time;
echo "<br>";
// echo date('Y/m/d' ,time());
//3連結資料庫
$link=mysqli_connect('127.0.0.1','root','root','day4');
mysqli_set_charset($link,'utf8');
$sqll="select * from zhu where phone='$phone'";
$results=mysqli_query($link,$sqll);
$count=mysqli_num_rows($results);
//修改
$sql="update zhu set phone='$phone','name'='$name','password'='$password',sex=$sex,time=$time where id=$id";
//echo $sql;
print_r($sql);
$result=mysqli_query($link,$sql);
if (!$result){
echo '修改失敗';
header('refresh:3,url=bian.php');
die();
}
//修改成功
echo '修改成功';
header('refresh:3,url=bian.php');
die();