您好,登錄后才能下訂單哦!
test.php
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
?>
===========================
add.php
<form method='POST' action='reg.php'>
用戶名:<input type='text' name='username'/>
密碼:<input type='password' name='pwd'/>
年齡:<input type='text' name='age'/>
<input type='submit' value='提交'>
<input type='reset' value='重新填寫'>
</form>
==============================
reg.php
<?php
require('test.php');
$username = $_POST['username'];
$pwd = $_POST['pwd'];
$age = $_POST['age'];
$uid = $redis->incr('userId');
$redis->hmset("user:".$uid,array('uid'=>$uid, 'username'=>$username, 'pwd'=>$pwd, "age"=>$age));
//print_r($redis->keys("*"))
header("location:list.php");
?>
=============
list.php
<?php
require('test.php');
$count = $redis->get('userId');
//echo $count;
for ($i=1; $i<=$count; $i++) {
// print_r($redis->hGetAll("user:".$i));
$data[] = $redis->hGetAll("user:".$i);
}
$data = array_filter($data);//過濾掉空數組(刪除造成的)
?>
<a href='add.php'>注冊</a>
<table border='1'>
<tr>
<th>姓名</th>
<th>密碼</th>
<th>年齡</th>
<th>操作</th>
</tr>
<?php
foreach ($data as $v) {
?>
<tr>
<td><?php echo $v['username'];?></td>
<td><?php echo $v['pwd'];?></td>
<td><?php echo $v['age'];?></td>
<td><a href="del.php?id=<?php echo $v['uid']; ?>">刪除</a><a href="modify.php?id=<?php echo $v['uid']; ?>">修改</a></td>
</tr>
<?php }
?>
</table>
=========================
del.php
<?php
require('test.php');
$uid = $_REQUEST['id'];
//$uid='10000';
$num = $redis->del("user:".$uid);
//echo $num;exit();
if ($num == 0) {
echo "刪除失敗";
} else {
header("location:list.php");
}
?>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。