PHP development message board tutorial registration function

Look at the code below

    注册  

会员注册

用户名:

密 码:

The registration page is submitted to regin.php, let’s analyze it

Link the database and introduce the file conn.php

require_once('conn.php');//Introducing the connection database file

When we write the registration, if the form submission information already exists in the database, it should not be allowed to register, for example: the database already has With the user "Zhang San", it is not advisable to use "Zhang San" when registering, so we first need to obtain the information submitted by the form, and then go to the database to query whether the information exists. The code is as follows:

$name = $_POST['username'];
$pwd = md5($_POST['password']);
$sql = "select * from user where username='$name'" ;
$info = mysql_query($sql);
$res = mysql_num_rows($info);

Then we have to judge $res. If it is true, the information exists in the database. Prompts that the user has been registered. is false, we can register and add the obtained information to the database

The code is as follows:

if($res){
echo "";
}else{
$sql1 = "insert into `user` (username,password) values(' $name','$pwd')";
$result = mysql_query($sql1);
if($result){
echo "";
}else{
echo ""; }else{ $sql1 = "insert into `user` (username,password) values('$name','$pwd')"; $result = mysql_query($sql1); if($result){ echo ""; }else{ echo ""; } } ?>


Continuing Learning
||
注册

会员注册

用户名:

密 码:

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!