Use PHP to achieve login and registration, and use PHP to read mysql Databases-display data in tables, phpmysql
Logon page
<Body>
<Form action = "login1.php" method = "post">
<Div> User name: <input type = "text" name = "uid"/> </div> <br/>
<Div> password: <input type = "password" name = "pwd"/> </div> <br/>
<Div> <input type = "submit" value = "Logon"/> </div>
</Form>
</Body>
Background login Processing
<? Php
$ Uid = $ _ POST ["uid"];
$ Pwd = $ _ POST ["pwd"];
$ Db = new MySQLi ("localhost", "root", "", "0710_info ");
If (mysqli_connect_error ()){
Die ("connection failed ");
}
$ SQL = "select pwd from users where uid = '{$ uid }'";
// Echo $ SQL;
$ Result = $ db-> query ($ SQL );
$ Arr = $ result-> fetch_row ();
// Prevent SQL injection attacks
If ($ arr [0] ==$ pwd &&! Empty ($ pwd )){
// Jump to the main interface (in php Mode)
Header ("location: register_system.php ");
// JS redirect page
/* Echo "<script>
Window. location. href = 'register _ system. php'
</Script> ";*/
} Else {
Header ("location: login_system.php ");
}
?>
Registration page
<Body>
<Form action = "register1.php" method = "post">
<Div>JS Form Verification
<Script>
Function check (){
Var uid = document. getElementsByTagName ("input") [0]. value;
If (uid = ""){
Alert ("Enter the user name! ");
Return false;
}
Var pwd = document. getElementsByTagName ("input") [1]. value;
If (pwd = ""){
Alert ("enter the password! ");
Return false;
}
Var name = document. getElementsByTagName ("input") [2]. value;
If (name = ""){
Alert ("enter your name! ");
Return false;
}
}
</Script>
Background registration Processing
<? Php
$ Uid = $ _ POST ["uid"];
$ Pwd = $ _ POST ["pwd"];
$ Name = $ _ POST ["name"];
$ Sex = $ _ POST ["sex"];
$ Db = new MySQLi ("localhost", "root", "", "0710_info ");
If (mysqli_connect_error ()){
Die ("connection failed ");
}
$ SQL = "insert into users values ('{$ uid}', '{$ pwd}', '{$ name}', {$ sex })";
$ R = $ db-> query ($ SQL );
If ($ r ){
Echo "registration successful! ";
} Else {
Echo "registration failed! ";
}
?>
PHP reads mysql database -- displays data in tables
<Body>
<Table width = "50%" border = "1">
<Tr>
<Td> Code </td>
<Td> name </td>
<Td> gender </td>
<Td> birthday </td>
<Td> ethnicity </td>
</Tr>
<? Php
$ Db = new MySQLi ("localhost", "root", "", "0710_info ");
$ SQL = "select info. code, info. name, sex, birthday, nation. name from info join nation on info. nation = nation. code"; // joint Query
$ Result = $ db-> query ($ SQL );
$ Arr = $ result-> fetch_all ();
// Var_dump ($ arr );
// Use foreach to traverse all data
Foreach ($ arr as $ v ){
$ Sex = $ v [2]? 'Male': 'female '; // determines gender by using the ternary Operator
Echo "<tr>
<Td >{$ v [0]} </td>
<Td >{$ v [1]} </td>
<Td> {$ sex} </td>
<Td >{$ v [3]} </td>
<Td >{$ v [4]} </td>
</Tr> ";
}
?>
</Table>
</Body>