For your help, I write the registration module according to the code in the book. Why can I register but not inquire about duplicate users?
I just learned php, know the meaning of the sentence, and when I encounter problems to post, it reminds me that I can not use the integral enough, that is, according to the book to write the mall project code registered users do not check the duplicate user name problem, it is strange that I do not check the duplicate user name when I write in it. I don't know why.
Teacher, this is the code in the book.
Database installer, database name is test, file name install.php
<?php // ini_set("error_reporting","E_ALL & ~E_NOTICE"); echo "<center>"; if (!isset($_POST["admin"])) { ?> <script language="javascript"> function check(f) { if (f.admin.value == "") { alert("Please enter the administrator name!"); f.admin.focus(); return (false); } if (f.pass.value == "") { alert("Please enter the administrator password!"); f.pass.focus(); return(false); } if (f.re_pass.value != f.pass.value){ alert("Duplicate password is not consistent with password!"); f.re_pass.focus(); f.re_pass.select(); return (false); } if (f.mail.value == "") { alert("Please enter the administrator's mailbox!"); f.mail.focus(); return (false); } if (f.type.value =="") { alert("Please enter the default commodity category!"); f.type.focus(); return(false); } } </script> <style type="text/css"> <!-- tr,td{font-size:12pt} --> </style> mini Mall Installation System<p> <table border="1" cellspacing="0" cellpadding="1" bordercolordark="#ffffff" bordercolorlight="#000000" width="300"> <form method=post action="<?php $_SERVER["PHP_SELF"]?>" onsubmit="return check(this)"> <tr> <td colspan=2 bgcolor="#cccccc" align="center"> Administrator Information </td> </tr> <tr> <td> Administrator name </td> <td> <input type=text name="admin"> </td> </tr> <tr> <td> Administrator password </td> <td> <input type=password name="pass" size=21> </td> </tr> <tr> <td> Confirm password </td> <td> <input type=password name="re_pass" size=21> </td> </tr> <tr> <td> Administrator mailbox </td> <td> <input type=text name="mail"> </td> </tr> <tr> <td colspan=2 bgcolor="#Cccccccc "align=" center "> commodity category information </td> </tr> <tr> <td> Default Category Name </td> <td> <input type=text name="type"> </td> </tr> <tr> <td> Default Category Introduction </td> <td> <input type=text name="description"> </td> </tr> <tr> <td colspan=2 align="center"> <input type="submit" value="Confirm installation"> </td> </tr> </form> </table> <?php } else { $admin=$_POST["admin"]; $pass=md5($_POST["pass"]); $mail=$_POST["mail"]; $type=$_POST["type"]; $description=$_POST["description"]; $time=date("Y year m month d day"); include "config.php"; $sql="create table $my_user( id int(5) not null auto_increment primary key, name varchar(12) not null default '', password varchar(40) not null default '', email varchar(80) not null default '', reg_date varchar(20) not null default '', admin enum('1','0')not null default '0' )ENGINE=InnoDB DEFAULT CHARSET = gb2312";//Must be gb2312 in the book $mysqli->query($sql) or die($mysqli -> error); $sql="create table $my_type( id int(5) not null auto_increment primary key, name varchar(12) not null default '', description varchar(80) not null default '', num int(5) not null default 0 )ENGINE=InnoDB DEFAULT CHARSET=gb2312"; $mysqli->query($sql) or die($mysqli -> error); $sql="create table $my_goods( id int(5) not null auto_increment primary key, name varchar(40) not null default '', type int(5) not null default 0, cost varchar(6) not null default '', description varchar(200) not null default '', num int(5) not null default 0 )ENGINE=InnoDB DEFAULT CHARSET=gb2312"; $mysqli->query($sql) or die($mysqli -> error); $sql="create table $my_sales( id int(5) not null auto_increment primary key, sale_user_name varchar(12) not null default '', sale_goods_id int(5) not null default 0, sale_goods_num int(5) not null default 0, sale_cost varchar(18) not null default '', sale_state enum('1','0') not null default '0', sale_date varchar(40) not null default '' )ENGINE=InnoDB DEFAULT CHARSET=gb2312"; //gb2312 $mysqli->query($sql) or die($mysqli->error); $sql="insert into $my_type(name,description)values('$type','description')"; $mysqli->query($sql) or die ($mysqli->error); $sql="insert into $my_user(name,password,email,reg_date,admin)values('$admin','$pass','$mail','$time',1)"; $re=$mysqli->query($sql) or die($mysqli->error); if($re) { echo "Background of installation module of mall system<p>"; echo "Successful installation mini Mall system!<p>"; echo "spot<a href=reg.php>Here</a>Register New User Points<a href=login.php>Here</a>Sign in"; } } echo "</center>"; //phpmyadmin encoding must be changed ?>
Configuration file config.php username root password 123456
<?php $host_name = "localhost"; $host_user = "root"; $host_pass = "123456"; $db_name = "test"; $my_user = "mini_user"; $my_type = "mini_type"; $my_goods = "mini_goods"; $my_sales = "mini_sales"; $mysqli = new mysqli($host_name,$host_user,$host_pass,$db_name); $mysqli->query("SET NAMES 'utf8'"); //Important directory database name can be changed, manually created, tentative utf8-bin coding test passed ?>
The previous installation is normal. The following reg.php problem has arisen. Users can be registered, but I don't understand it without looking up duplicate users. But the code has this function:
<?php echo "<center>"; if(!isset($_POST["name"])) { ?> <script language="javascript"> function check(f) { if(f.name.value=="") { alert("Please enter the registered user name!"); f.name.focus(); return(false); } if (f.pass.value=="") { alert("Please enter the registered user password!"); f.pass.focus(); return(false); } if(f.re_pass.value!=f.pass.value) { alert("Duplicate password is not consistent with password!"); f.re_pass.focus(); f.re_pass.select(); return (false); } if(f.mail.value=="") { alert("Please enter the registered user's mailbox!"); f.mail.focus(); return(false); } } </script> <style type="text/css"> <!-- tr,td{font-size:12pt} --> </style> mini Mall System Registration Procedure<p> <table border="1" cellspacing="0" cellpadding="1" bordercolordark="#ffffff" bordercolorlight="#000000" width="300"> <form method=post action="<?php $_SERVER["PHP_SELF"]?>" onsubmit="return check(this)"> <tr> <td colspan="2" bgcolor="#Cccccccc "align=" center "> registered user information </td> </tr> <tr> <td> Registered User Name </td> <td> <input type=text name="name"></td> </td> </tr> <tr> <td>Registered User Password</td> <td><input type=password name="pass" size=21></td> </tr> <tr> <td>Confirm password</td> <td><input type=password name="re_pass" size=21></td> </tr> <tr> <td>Registered User Mailbox</td> <td><input type=text name="mail"></td> </tr> <tr> <td colspan=2 align="center"><input type="submit" value="register"></td> </tr> </form> </table> <?php } else { $name=$_POST["name"]; $pass=md5($_POST["pass"]); $mail=$_POST["mail"]; $time=date("Y year m month d day"); include "config.php"; $sql="SELECT count(*) FROM $my_user WHERE name='$name'"; $re=$mysqli->query($sql) or die($mysqli->error); $count=$re->num_rows;//Get the number of users with the same name if($count[0]>0) //If there is a user with the same name { echo "Same name user already exists<p>"; echo "spot<a href=reg.php>Here</a>Register New User Points<a href=login.php>Here</a>Sign in"; } else { $sql="INSERT INTO $my_user(name,password,email,reg_date)values('$name','$pass','$mail','$time')"; $re=$mysqli->query($sql) or die($mysqli->error); if ($re) { echo "Successful registered users:".$name."<p>"; echo "spot<a href=login.php>Here</a>Sign in"; # code... } } } echo "</center>"; echo exit; ?>
It is the successful registration, but does not prompt the registration of reusable users, I read the database, I registered a bunch of the same users, why duplicate check does not work?
I used win7 64 wamp
php5.6.31
mysql5.7.19
Thank you!