PHP Add user simple PHP starter Tutorial

Source: Internet
Author: User
Tags mysql tutorial

<?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>

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.