|
// 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> "; |