PHP串連資料庫實現註冊頁面的增刪改查操作,php增刪_PHP教程

來源:互聯網
上載者:User

PHP串連資料庫實現註冊頁面的增刪改查操作,php增刪


本文執行個體為大家分享了PHP串連資料庫實現註冊頁面的增刪改查操作的方法,供大家參考,具體內容如下

1.串連資料庫

<?php //本地測試 $host = '127.0.0.1'; $port = 3306; $user = "root"; $pwd = ""; $link = @mysql_connect("{$host}:{$port}",$user,$pwd,true); if(!$link) {  die("Connect Server Failed: " . mysql_error()); } //選擇串連的資料庫庫名 mysql_select_db("my"); //設定字元編碼utf8 mysql_set_charset('utf8');?>

2.註冊頁面(html頁面)

  Document

註冊頁面

3.將註冊資料顯示在資料庫

//往資料庫中添加資料<?phpheader("Content-type:text/html; charset=utf-8");//-----------------------串連資料庫---------------------------include_once "connect.php";//-------------------------將資料連線到資料庫------------------$time=time();$sql="insert into user (username,password,email,sex,txt,`time`) value('{$_POST['username']}','{$_POST['password']}','{$_POST['email']}','{$_POST['sex']}','{$_POST['txt']}','{$time}')";$res=mysql_query($sql);header("location:hello.php");?>

4.返回後台介面

<?phpheader("Content-type:text/html; charset=utf-8");//-----------------------串連資料庫------------------------------include_once "connect.php";//--------------------查詢資料庫--------------------------------$query="select * from user";$result=mysql_query($query);if(!$result){ die("could not to the database
".mysql_error());}//-------------------封裝函數-----------------------------//該函數將資料庫的資料寫成數組形式function result2Arr($result){ while($result_row=mysql_fetch_assoc($result)){ $arr[] = $result_row; } return $arr;}$arr = result2Arr($result);foreach($arr as $key=>$value){ echo " "; echo "
"; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo "
".$value['id']."".$value['username']."".$value['password']."".$value['email']."".$value['sex']."".$value['txt']."".date('Y-m-d H:i:s',$value['time'])."修改 刪除
";}?>

5.修改資料

//當使用者要修改資訊時,返回頁面,頁面中包含之前填寫的資訊  Document<?php include_once "connect.php"; $sql="select * from user where id='".$_GET['id']."'"; //echo "sql:".$sql;(顯示出修改哪一行) $result=mysql_query($sql,$link); $arr = result2Arr($result); //print_r($arr); $row = $arr[0];function result2Arr($result){ while($result_row=mysql_fetch_assoc($result)){  $arr[] = $result_row; } return $arr;}?>  

註冊頁面

//將修改的資訊存入資料庫<?phpheader("Content-type:text/html; charset=utf-8");//通過post擷取頁面提交資料資訊$data = $_POST;//print_r($data);include_once "connect.php";$sql = "update `user` set username='{$data['username']}',password='{$data['password']}', email='{$data['email']}',sex='{$data['sex']}',txt='{$data['txt']}' where id='{$data['id']}'";echo $sql;$res = mysql_query($sql,$link);if($res){ header("Location:hello.php"); //echo "alert('修改成功')";}else{ header("Location:update1.php?id=".$data['id']); //echo "alert('修改失敗')";}?>

6.刪除資料

//刪除資料庫裡的資料<?phpheader("Content-type:text/html; charset=utf-8");include_once 'connect.php';$sql = "delete from user where id='".$_GET['id']."'";$sus=mysql_query($sql,$link);if($sus){ header("location:hello.php");}else{ echo "alert('刪除失敗')";}?>//若要刪除李四,點擊刪除後,會自動跳轉到後台頁面,資料庫裡資料也刪除

以上就是本文的全部內容,希望對大家的學習有所協助。

您可能感興趣的文章:

  • 註冊頁面之前先驗證使用者名稱是否存在的php代碼
  • 用Php編寫註冊後Email啟用驗證的執行個體代碼
  • php使用者註冊頁面利用js進行表單驗證具體執行個體
  • ThinkPHP之使用者註冊登入留言完整執行個體
  • PHP+Ajax檢測使用者名稱或郵件註冊時是否已經存在執行個體教程
  • PHP+jQuery 註冊模組開發詳解
  • PHP+jQuery 註冊模組的改進(一):驗證碼存入SESSION
  • PHP+jQuery 註冊模組的改進(二):郵箱啟用
  • php+mysql實現使用者註冊登陸的方法
  • php傳送簡訊驗證碼完成註冊功能

http://www.bkjia.com/PHPjc/1114240.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1114240.htmlTechArticlePHP串連資料庫實現註冊頁面的增刪改查操作,php增刪 本文執行個體為大家分享了PHP串連資料庫實現註冊頁面的增刪改查操作的方法,供大家參考...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.