<?php
Data
CREATE TABLE IF not EXISTS ' Leo_user ' (
' id ' int (one) not NULL auto_increment,
' Name ' char (not NULL),
' Birthday ' date not NULL,
' Email ' char ' not NULL,
' Sex ' enum (' M ', ' F ', '-') not NULL,
PRIMARY KEY (' id '),
UNIQUE KEY ' email ' (' email ')
) Engine=myisam DEFAULT Charset=utf8 auto_increment=5;
--
--Export the data in the table ' Leo_user '
--
INSERT into ' leo_user ' (' id ', ' name ', ' birthday ', ' email ', ' sex ') VALUES
(1, ' John ', ' 1980-01-01 ', ' zhangshan@email.com ', ' M '),
(2, ' Dick ', ' 1998-01-25 ', ' lisi@test.com ', ' M '),
(3, ' Harry ', ' 1985-12-24 ', ' wangwu@leophp.cn ', '-'),
(4, ' Zhao Liu ', ' 1978-05-05 ', ' zhaoliu@test.com ', ' F ');
function Db_exec ($sql) {
$resource = MySQL Tutorial _connect (db_host, Db_user, Db_password); Connecting to a database tutorial
mysql_query ("SET NAMES '"). Db_charset. "' ;"); Set Font Set
$connect = mysql_select_db (db_name, $resource); Select Database
Return mysql_query ($sql, $resource); Execute SQL
}
if ($_post[' op '] = = ' Add ') {
$sql = "
INSERT into. " Table_prefix. "User (
Name
Birthday,
Email
Sex)
VALUES (
'" . $_post[' name '. "',
'" . $_post[' birthday ']. "',
'" . $_post[' email '. "',
'" . $_post[' sex ']. "'
)";
if (Db_exec ($sql)) {
$notice = Array (
' msg ' => ' added success ',
' Alt ' => ' list user ',
' URL ' => '? Op=index '
);
Require_once www.111cn.net/_notice.phtml ';
} else {
$notice = Array (
' msg ' => ' added failed ',
' Alt ' => ' Add user ',
' URL ' => '? Op=add '
);
Require_once www.111cn.net/_notice.phtml ';
}
} else {
Require_once ' view/add.phtml ';
}
add.phtml Template page
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> User Add </title>
<body>
<form action= "? Op=add" method= "post" enctype= "application/x-www-form-urlencoded" >
Name: <input type= "text" name= "name" size= "/><br/>
Birthday: <input type= "text" name= "Birthday" size= "ten"/> (yyyy-mm-dd) www.111cn.net<br/>
E-mail: <input type= "text" name= "email" size= "/><br/>
Sex: <input type= "Radio" name= "Sex" value= "3"/> Confidential
<input type= "Radio" name= "Sex" value= "1"/> Male
<input type= "Radio" name= "Sex" value= "2"/> Women <br/>
<input type= "hidden" name= "Op" value= "Add"/><br/>
<input type= "Submit" name= "Submit" value= "Add User"/>
</form>
<?php require_once ' view/_foot.phtml ';?>
</body>