Php simple registration code

Source: Internet
Author: User
Tags mysql tutorial
The code is as follows: Copy code

<Script language = "webpage effect">
Function checkreg ()
    {    
If (form1.name. value = "")
  {
// If the real name is empty, a warning is displayed.
Alert ("real name cannot be blank! ");
Form1.name. focus ();
Return false;
     }
If (form1.password. value = "")
  {
// If the password is empty, a warning is displayed.
Alert ("The password cannot be blank! ");
Form1.password. focus ();
Return false;
     }
If (form1.pwd. value = "")
  {
// If the password is empty, a warning is displayed.
Alert ("The password cannot be blank! ");
Form1.pwd. focus ();
Return false;
     }
// The two passwords should be the same
If (form1.password. value! = Form1.pwd. value & form1.password. value! = "")
  {
Alert ("two passwords are different. Please confirm! ");
Form1.password. focus ();
Return false;
  }
If (form1.email. value = "")
  {
// If the email is empty, a warning is displayed.
Alert ("email cannot be blank! ");
Form1.email. focus ();
Return false;
     }
// Check whether the email format is correct
Else if (form1.email. value. charat (0) = "." |
Form1.email. value. charat (0) = "@" |
Form1.email. value. indexof ('@', 0) =-1 |
Form1.email. value. indexof ('.', 0) =-1 |
Form1.email. value. lastindexof ("@") = form1.email. value. length-1 |
Form1.email. value. lastindexof (".") = form1.email. value. length-1)
  {
Alert ("the email format is incorrect! ");
Form1.email. select ();
Return false;
  }
Return true;

    } 
</Script>

<Html>
<Body>

<Form name = "form1" method = "post" action = "regok. php" enctype = 'multipart/form-data' onsubmit = "return checkreg ()">
<Table border = "0" cellspacing = "1" cellpadding = "3" align = "center">
<Tr>
<Th colspan = "2"> <font size = "5"> user registration </font> </th>
</Tr>
<Tr>
<Td> last name: </td>
<Td>
<Input type = "text" name = "name">
</Tr>
<Tr>
<Td> Password: </td>
<Td>
<Input type = "password" name = "password">
</Tr>
<Tr>
<Td> Confirm password: </td>
<Td>
<Input type = "password" name = "pwd">
</Tr>
<Tr>
<Td> email: </td>
<Td>
<Input type = "text" name = "email">
</Tr>
<Tr>
<Td> Telephone: </td>
<Td>
<Input type = "text" name = "tel">
</Tr>
<Tr>
<Td> address: </td>
<Td>
<Input type = "text" name = "address">
</Tr>
<Tr>
<Td align = right>
<Input type = "submit" name = "submit" value = "">
</Td>
<Td align = center>
<Input type = "reset" name = "submit2" value = "re-write">
</Td>
</Tr>
</Table>
</Form>

</Body>

</Html>

<? Php

The code is as follows: Copy code

// Initialize the session
Session_start ();
// Contains the database tutorial connection file and header file
$ Conn = mysql tutorial _ connect ("localhost", "phpdb", "phpdb ")
Or die ("cannot connect to the database server:". mysql_error ());
Mysql_select_db ("book", $ conn) or die ("The database cannot be selected:". mysql_error ());
?>
<? Php
// Obtain the webpage parameters
$ Name = $ _ post ['name'];
$ Password = $ _ post ['password'];
$ Email = $ _ post ['email '];
$ Tel = $ _ post ['tel'];
$ Address = $ _ post ['address'];

// Encrypted password
$ Password = md5 ($ password );

// Connect to the database and register the user
$ SQL = "insert into user (name, password, email, tel, address) values ('$ name',' $ password', '$ mail',' $ Tel ', '$ address ')";
Mysql_query ($ SQL, $ conn) or die ("failed to register a user:". mysql_error ());

// Obtain the automatic id of the registered user. You can use this id to log on later.
$ Result = mysql_query ("select last_insert_id ()", $ conn );
$ Re_arr = mysql_fetch_array ($ result );
$ Id = $ re_arr [0];

// Register successfully, automatically log on, and register session variables
Session_register ("user ");
$ User = $ id;
Echo "<table align = center> <tr> <td align = center> registration successful! </Td> </tr> ";
Echo "<tr> <td align = center> <font color = red> your registration id is:". $ id;
Echo ", please remember, use this id to log on later! </Font> </td> </tr> </table> ";

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.