PHP paging and regular verification code implementation
This article introduces you to the code implementation of PHP paging and regular verification. It has a good reference value and I hope it can help friends in need.
Paging:
<?php header("Content-type:text/html;Charset=utf8"); $link=mysqli_connect("localhost:3306","root","root","weektwo"); if(!$link) echo "连接失败的原因是:" . mysqli_connect_error(); mysqli_query($link,"set names utf8"); $tiao=4; $sql="select count(*) from kao"; $res=mysqli_query($link,$sql); $zong=mysqli_fetch_assoc($res); $z=count($zong); $max=ceil($z/$tiao); if(!$_GET['page']){ $page=1; }else{ if($page<1){ $page=1; }elseif($page>$max){ $page=$max; }else{ $page=$_GET['page']; } } $ye=($page-1)*$tiao; $sql="select * from kao where limit ".$ye.",".$tiao; $a=mysqli_query($link,$sql); while($res=mysqli_fetch_assoc($a)){ $arr[]=$res; } // var_dump($arr);die; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <table border="1"> <tr> <td>编号</td> <td>姓名</td> <td>分类</td> <td>单价</td> <td>状态</td> <td>库存</td> <td>产地</td> </tr> <?php foreach($arr as $key => $v) {?> <tr> <td><?php echo $v['id']?></td> <td><?php echo $v['name']?></td> <td><?php echo $v['fen']?></td> <td><?php echo $v['dj']?></td> <td><?php echo $v['zhuang']?></td> <td><?php echo $v['kucun']?></td> <td><?php echo $v['chan']?></td> </tr> <?php }?> <a href="1.php?page=1">首页</a> <a href="1.php?page=<?php echo $page-1;?>">上一页</a> <a href="1.php?page=<?php echo $page+1;?>">下一页</a> <a href="1.php?page=<?php echo $max;?>">尾页</a> </table> </body> </html>
Regular verification:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>正则</title> </head> <body> <form action="" onsubmit="fun()"> <table border="1"> <tr> <td>姓名</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>性别</td> <td> <input type="radio" name="sex">男 <input type="radio" name="sex">女 </td> <td width="200"><span></span></td> </tr> <tr> <td>密码</td> <td><input type="text" id="xm"></td> <td width="200"><span></span></td> </tr> <tr> <td>确认密码</td> <td><input type="text" id="xm"></td> <td width="200"><span></span></td> </tr> <tr> <td>邮箱</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>城市</td> <td> <select name="a4" id="o" onclick="fun1()"> <option value="">请选择</option> <option value="0" >北京</option> <option value="1">上海</option> <option value="2">衡水</option> <option value="3">石家庄</option> </select> </td> <td width="200"><span></span></td> </tr> <tr> <td>手机号</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>座机号</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>身份证号</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>QQ号</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>自我介绍</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td><input type="submit" value="登录"></td> <td><input type="submit" value="重置"></td> </tr> </table> </form> <script> var inp = document.getElementsByTagName('input'); var sp = document.getElementsByTagName('span'); var o = document.getElementsByTagName('option'); var reg = /^[a-zA-Z][a-zA-Z0-9]{4,9}$/; var pass =/^[a-zA-Z0-9_]{6,}$/; var p=/^[0-9]+[a-zA-Z]{3,}$/; var emile =/^[a-zA-Z0-9]+@[a-zA-Z0-9](\.)(.net|cn){2,6}$/; var tel =/^1[5|8|3][0-9]{9}$/; var qq= /^[0-9]{8,11}$/; var t=/^[0-9][0-9][0-9]-[0-9]{8}$/; var shen=/^[0-9]{14,17}[0-9X]$/; var te=/^[0-9a-zA-Z_]{0,20}$/; var city=/^[0-9]$/; inp[0].onblur = function (){ //console.log(inp[0].value); if(!reg.test(inp[0].value)){ sp[0].innerText = "必须由5到10位数字或字母组成,不允许数字开头"; }else{ sp[0].innerText= "√"; } } inp[3].onblur = function (){ if(!pass.test(inp[3].value)){ sp[2].innerText = "密码必须在6位以上"; }else{ sp[2].innerText= "√"; } } inp[3].onblur = function (){ if(!pass.test(inp[3].value)){ sp[2].innerText="密码必须6位以上"; }else{ sp[2].innerText="√"; } } inp[4].onblur = function (){ if(inp[3].value!=inp[4].value){ sp[3].innerText = "确认密码和密码必须一致"; }else{ sp[3].innerText= "√"; } } function fun(){ var sex=document.getElementsByName('sex'); if(!sex[0].checked && !sex[1].checked){ sp[1].innerText="必选一项"; }else{ sp[1].innerText= "√"; } } inp[5].onblur = function (){ if(!emile.test(inp[5].value)){ sp[4].innerText = "必须包含@符号或者cn或者.net结尾"; }else{ sp[4].innerText= "√"; } } inp[6].onblur = function (){ if(!tel.test(inp[6].value)){ sp[6].innerText = "必须是11位数字开头,以15,18,13开头"; }else{ sp[6].innerText= "√"; } } inp[7].onblur = function (){ if(!t.test(inp[7].value)){ sp[7].innerText = "必须是010-68801717这种格式,前面三位是区号,后面是8位电话号,中间是-"; }else{ sp[7].innerText= "√"; } } inp[8].onblur = function (){ if(!shen.test(inp[8].value)){ sp[8].innerText = "必须是15到18位数字组成,18位的最后一位可以是X"; }else{ sp[8].innerText= "√"; } } inp[9].onblur = function (){ if(!qq.test(inp[9].value)){ sp[9].innerText = "必须是8到11位数字组成"; }else{ sp[9].innerText= "√"; } } inp[10].onblur = function (){ if(!te.test(inp[10].value)){ sp[10].innerText = "必须是8到11位数字组成"; }else{ sp[10].innerText= "√"; } } function fun1(){ var o=document.getElementById('o'); if(!city.test(o.value)){ sp[5].innerText = "必选一项"; return false; }else{ sp[5].innerText= "√"; return true; } } </script> </body> </html>
Related recommendations:
PHP regular verification email method, PHP verification Email method
PHP paging class code, php paging code
The above is the detailed content of PHP paging and regular verification code implementation. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.
