PHP 初学之登录查询小case
2016-07-19 11:10
429 查看
说明:如误入本文,请忽略即可,内容仅为记录。
功能:登录(不验证),查询所有列表,删除记录。--很简单,仅为熟悉代码。
// MySQL,新建数据库data,导入如下sql
//新建login页面
//新建welcome页面
//新建list页面
//新建del页面
功能:登录(不验证),查询所有列表,删除记录。--很简单,仅为熟悉代码。
// MySQL,新建数据库data,导入如下sql
SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for stu -- ---------------------------- DROP TABLE IF EXISTS `stu`; CREATE TABLE `stu` ( `stuid` int(11) NOT NULL AUTO_INCREMENT, `stuname` varchar(20) NOT NULL, `stusex` char(1) NOT NULL, `stuage` tinyint(4) NOT NULL, `stuadd` varchar(100) NOT NULL, PRIMARY KEY (`stuid`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='学生表'; -- ---------------------------- -- Records of stu -- ---------------------------- INSERT INTO `stu` VALUES ('1', '篱笆', '男', '18', '北京'); INSERT INTO `stu` VALUES ('2', '绾绾', '女', '13', '上海');
//新建login页面
<?php if (isset($_POST['username']) && isset($_POST['pwd'])) { header("location:welcome.php?username={$_POST['username']}"); }else{ echo '用户名或密码不能为空!<br/>'; } ?> <form action="" method="post"> <table> <tr> <td>用户名:</td> <td>密码</td> </tr> <tr> <td><input type="text" name="username"></td> <td><input type="password" name="pwd"></td> </tr> <tr> <td><input type="submit" name="submit"></td> </tr> </table> </form>
//新建welcome页面
welcome! user: <b> <?php if (isset($_GET['username'])) { echo $_GET['username']; } ?> </b> <br/> <script type="text/javascript"> function go(){ location.href='list.php'; } </script> <input type="button" value="query list" onclick="go()"/>
//新建list页面
<script type="text/javascript"> function del(id){ location.href='del.php?id='+id; } </script> <table> <tr> <th>stuid</th> <th>stuname</th> <th>stusex</th> <th>stuage</th> <th>stuadd</th> </tr> <?php $link = mysqli_connect('localhost','yourusername','yourpwd') or die(mysql_error()); mysqli_select_db($link, 'data') or die(mysql_error); mysqli_query($link, 'set names utf8'); $rs = mysqli_query($link, 'select * from stu'); while ($row = mysqli_fetch_array($rs)) { $id = $row['stuid']; echo "<tr>"; echo "<td>".$row['stuid']."</td>"; echo "<td>".$row['stuname']."</td>"; echo "<td>".$row['stusex']."</td>"; echo "<td>".$row['stuage']."</td>"; echo "<td>".$row['stuadd']."</td>"; echo "<td>"."<a href='javascript:void()' onclick='del({$id})'>删除(不要点啊)</a>"."</td>"; echo "</tr>"; } ?> </table>
//新建del页面
<?php if(isset($_GET['id'])){ $link = mysqli_connect('localhost','yourusername','yourpwd') or die(mysql_error); mysqli_select_db($link, 'data') or die(mysql_error); $rs = mysqli_query($link, "delete from stu where stuid = {$_GET['id']}"); var_dump($rs); echo "已经成功删除了id为{$_GET['id']}的记录<br/>"; } ?>
相关文章推荐
- Laravel SQL 查询语句集锦
- Yii整合ZF2中Feed模块
- php升级
- 530 Non-anonymous session must use encryption FTP连接出现的问题
- 一些php魔术方法;
- thinkphp 页面提交参数的过滤(转义)
- PHP实现数组array转换成xml的方法
- PHPunit和CI框架整合
- Laravel 资源汇总
- Thinkphp 连接数据库、查询、添加
- 分析PHP的死锁问题
- PhpStorm中如何使用Xdebug工具,入门级操作方法
- PHP利用超级全局变量$_POST来接收表单数据。
- 2.PHP-开发环境,开发工具,数据库管理
- Solaris 10 开启/关闭SFTP服务、SSH服务
- Solaris 10 开启FTP服务
- Ubuntu下PHP的扩展
- php定时任务
- PHP中Socket连接及读写数据超时问题分析
- 10. PHP 图像填充 imagefill、imagefilledarc 与 imagefilledrectangle() 函数