PHP implementation MySQL database connection operation and user management, MySQL database connection _php Tutorial

Source: Internet
Author: User

PHP implementation MySQL database connection operation and user management, MySQL database connection


File list: File contents:
dbconn.php
userlistt.php
edituser.php
editdo.php
detailuser.php
deleteuser.php
adduser.php
adddo.php

<?php//CREATE DATABASE connection $con = mysql_connect ("localhost", ' root ', ') or Die (' ERROR: '. mysql_error ()); mysql_select_db (' Hyxx ') , $con) or Die (' ERROR: '. mysql_error ()); mysql_query (' Set NAMES utf8 ');? >

userlistt.php

 
  
 <title>Member Information List</title>      
 
 <?phprequire_once ' inc/dbconn.php ';//What Is this stuff? Date_default_timezone_set ("PRC");//Read data ... $sql = "SELECT * from the user ORDER by ID ASC"; $result = mysql_query ($sql, $con); $userList = "; while ($rs = Mysql_fetch_array ($result)) {$userList [] = $rs; }//Cyclic user list foreach ($userList as $user) {echo ' 
   "; }?> 
  
Id User name Password Gender Age Date of birth Hobby Registration time Last logon time Operation
". $user [' id ']." ". $user [' username ']." ". $user [' Password ']." ". $user [' sex ']." ". $user [' age ']." ". Date (" y-m-d ", $user [' Birthday '])." ". $user [' Hobby ']." ". Date (" y-m-d ", $user [' Add_time '])." ". Date (" y-m-d ", $user [' Last_login '])." The deletion of the changes to the search

edituser.php

 
  Edit User<?php require_once ' inc/dbconn.php '; $userId =$_get[' id '];//What's this stuff? Date_default_timezone_set ("PRC");//Read data ...  $sql = "SELECT * from user where id=". $userId;  $result = mysql_query ($sql, $con);  $user = Mysql_fetch_array ($result);? >

editdo.php

<?phprequire_once ' inc/dbconn.php ';///////////////////////get user information////////////////////$user _id = $_POST[' User_ Id ']; $user _name = $_post[' user_name '); $password = $_post[' password '];if ($_post[' sex ']== ' man ') {$sex = 1;} else if ($_post[' sex ']== ' female ') {$sex = 2;}    else $sex = 3; ; $age = $_post[' age '); $birthday _y = $_post[' birthday_y '); $birthday _m = $_post[' birthday_m ']; $birthday _d = $_post[' Birthday_d ']; $birthday =mktime (0,0,0, $birthday _m, $birthday _d, $birthday _y); $hobby = $_post[' hobby ']; $profile = $_ post[' profile '; $addTime =mktime (Date ("H"), Date ("M"), date ("s"), date ("M"), Date ("D"), Date ("Y")), $lastLoginTime =$  Addtime; $sql = "Update user set Username= ' $user _name ', password= ' $password ', sex= ' $sex ', age= ' $age ', birthday= ' $birthday ', hobby  = ' $hobby ', profile= ' $profile ' where id= ' $user _id ' ";  Echo $sql;  Execute SQL statement mysql_query ($sql, $con);  Gets the number of rows affected $rows = Mysql_affected_rows ();    Returns the number of rows affected//If the number of rows >=1 is affected, the judgment is added successfully, otherwise fails if ($rows >= 1) {alert ("Edit succeeded");  href ("userlistt.php"); }else{alert ("Edit failed");//href (" adduser.php "); }function Alert ($title) {echo "";} function href ($url) {echo "";}? >

detailuser.php

 
  
 <title>View User Details</title><?php require_once ' inc/dbconn.php '; $userId =$_get[' id '];//What's this stuff?  Date_default_timezone_set ("PRC");//Read data ...  $sql = "SELECT * from user where id=". $userId;  $result = mysql_query ($sql, $con); $user = Mysql_fetch_array ($result);? >
 
 
User ID <?php Echo $userId?>
User name <?php echo $user [' username ']?>
Password <?php echo $user [' Password ']?>
Gender <?php if ($user [sex]== ' 1 ') echo "male"; else if ($user [sex]== ' 2 ') echo "female"; Else "Confidential";?>
Age <?php echo $user [' age ']?>
Date of birth <?php $birday _y=date ("y", $user [' birthday ']); Echo $birday _y. " Years "; $birday _m=date ("M", $user [' birthday ']); Echo $birday _m. " Month "; $birday _d=date ("D", $user [' birthday ']); Echo $birday _d. " Day "; ?>
Hobby <?php echo $user [' hobby ']?>
Personal profile <?php echo $user [' profile ']?>
Back to User list

deleteuser.php

<?php//contains the database file require_once ' inc/dbconn.php ';//get deleted id$id = $_get[' id ']; $row = delete ($id, $con); if ($row >=1) {  Alert ("Delete succeeded");} else{  alert ("Delete failed");} Jump to the User List page href ("userlistt.php"), function Delete ($id, $con) {  $sql = "Delete from user where id= ' $id '";  Execute Delete  mysql_query ($sql, $con);  Gets the number of rows affected  $rows = Mysql_affected_rows ();  Returns $rows affecting the number of rows returned  ;} Function alert ($title) {  echo "";} function href ($url) {  echo "";}? >

adduser.php

 
  New user

adddo.php

<?php require_once ' inc/dbconn.php ';///////////////////////get user information////////////////////$user _id = $_POST[' User_ Id ']; $user _name = $_post[' user_name '];echo $user _name; $password = $_post[' password '];if ($_post[' sex ']== ' man ') {$sex = 1;} else if ($_post[' sex ']== ' female ') {$sex = 2;}    else $sex = 3; ; $age = $_post[' age '); $birthday _y = $_post[' birthday_y '); $birthday _m = $_post[' birthday_m ']; $birthday _d = $_post[' Birthday_d ']; $birthday =mktime (0,0,0, $birthday _m, $birthday _d, $birthday _y); $hobby = $_post[' hobby ']; $profile = $_ post[' profile '; $addTime =mktime (Date ("H"), Date ("M"), date ("s"), date ("M"), Date ("D"), Date ("Y")), $lastLoginTime =$  Addtime;  $sql = "INSERT into user (Username,password,sex,age,birthday,hobby,profile,add_time,last_login)".  "Values (' $user _name ', ' $password ', ' $sex ', ' $age ', ' $birthday ', ' $hobby ', ' $profile ', ' $addTime ', ' $lastLoginTime ')";  Echo $sql;  Execute SQL statement mysql_query ($sql, $con);  Gets the number of rows affected $rows = Mysql_affected_rows (); Returns the number of rows affected//If the number of rows >=1 is affected, the judgment is added successfully, otherwise fails if ($rows >= 1) {AlerT ("add success");  href ("userlistt.php");    }else{alert ("Add failure");//href ("adduser.php"); }function Alert ($title) {echo "";} function href ($url) {echo "";}? >

http://www.bkjia.com/PHPjc/1069353.html www.bkjia.com true http://www.bkjia.com/PHPjc/1069353.html techarticle PHP Implementation MySQL database connection operation and user management, MySQL database connection file list. File contents: dbconn.php userlistt.php edituser.php editdo.php detailuser.php delet ...

  • 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.