SQL Script create database example use example create
資料庫規劃 SQL Script create database example; use example; create table member(serial int unsigned not null primary key auto_increment, id varchar(30) unique key not null , passwd varchar(20) not null, status int unsigned not null, rank int unsigned not null); insert into member values('', 'adm 123456', 1, 100); n n n 建立example資料庫 建立member資料表 並建立adm/adm 123456管理者
sql_connect. php <? /* Connecting, selecting database */ $link = mysql_connect('localhost', 'root', '123456') or die("Could not connect : ". mysql_error()); //echo "Connected successfully"; mysql_select_db("example") or die("Could not ") select database"); ? >
my_msg. php <? Function my_header($redirect){ my_header($redirect) echo "<script language="javascript">"; echo "location. href='". $redirect. "'"; echo "</script>"; return; } Function my_msg($msg, $redirect){ echo "<SCRIPT Language=javascript>"; echo "window. alert('". $msg. "')"; echo "</SCRIPT>"; echo "<script language="javascript">"; echo "location. href='". $redirect. "'"; echo "</script>"; return; } ? >
會員註冊:表單 (節錄) add. html …. . <form name="form 1" action=add_chk. php method=post> add_chk. php <p align="center">請輸入您要使用的帳號:<input type="text" name="id"></p> id <p align="center">請輸入您要使用的密碼:<input type="password" name="passwd"></p> passwd <p align="center">請重複輸入您的密碼以確認:<input type="password" name="repasswd"></p> repasswd <p align="center"><input type="submit" name="送出"><input type="reset" name="重設"></p> </form> ….
會員註冊:判斷程式(節錄) add_chk. php <? include_once("sql_connect. php"); include_once("my_msg. php"); ? > …
會員註冊:判斷程式(節錄) add_chk. php … $sqlstr="insert into member values('', '". $_POST['id']. "', '". $_POST['passwd']. "', 1, 1)"; //組合 sql $result=mysql_query($sqlstr, $link); //執行 sql //跳至檢視頁 my_msg("新增使用者成功,請以此使用者帳號/密碼重新登入 ", "login. html"); mysql_free_result($result); mysql_close($link); ? >
會員登入:表單(節錄) login. html … <form name="form 1" action=login_chk. php method=post> <p align="center">請輸入您的帳號:<input type="text" name="id"></p> id <p align="center">請輸入您的密碼:<input type="password" name="passwd"></p> passwd <p align="center"><input type="submit" name="送出"><input type="reset" name="重設"></p> </form> …
會員登入:判斷程式(節錄) login_chk. php … if($_POST['id']=='' or $_POST['passwd']==''){ ']=='' my_msg("欄位不可空白", "login. html"); } $sqlstr="select * from member where id ='". $_POST['id']. "' and passwd = '". $_POST['passwd']. "' and status = 1"; 1 $result = mysql_query($sqlstr, $link); …
會員登入:判斷程式(節錄) login_chk. php $row = mysql_fetch_array($result, MYSQL_BOTH); if(mysql_num_rows ($result)==1 && $row["rank"]==100){ $row["rank"]==100 setcookie("cookie_chk", "adm_logined"); setcookie("cookie_id", $_POST['id']); my_header("adm. php"); // 管理者登入 adm. php }elseif(mysql_num_rows ($result)==1 && $row["rank"]==1){ $row["rank"]==1 setcookie("cookie_chk", "logined"); setcookie("cookie_id", $_POST['id']); my_header("main. php"); // 會員登入 "main. php }else{ my_msg("登入失敗,請重新登入", "login. html"); }
會員修改資料:表單(節錄) mod. html … <form name="form 1" action=mod_chk. php method=post> <p align="center">請輸入新的密碼:<input type="password" name="passwd"></p> <p align="center">請重複輸入新的以確認:<input type="password" name="repasswd"></p> <p align="center"><input type="submit" name="送出 "><input type="reset" name="重設"></p> </form> …
會員修改資料:判斷程式(節錄) mod_chk. php …. if($_POST['passwd']=='' or $_POST['repasswd']==''){ my_msg("欄位不可空白", "mod. html"); } if($_POST['passwd']!=$_POST['repasswd']){ my_msg("密碼並不相符,需重複鍵入相同密碼以確認", "mod. html"); } if (isset($_COOKIE['cookie_id'])) { $sqlstr="update member set passwd ='". $_POST['passwd']. "' where id = '". $_COOKIE['cookie_id']. "'"; //組合 sql }else{ my_msg("登入異常,無法取得 id,請重新登入", "login. html"); } …
管理者刪除會員:表單(節錄) del. php … <? if (isset($_COOKIE['cookie_chk'])) { if($_COOKIE['cookie_chk']!="adm_logined"){ my_msg("登入失敗,請重新登入", "login. html"); } }else{ my_msg("登入失敗,請重新登入", "login. html"); } …
管理者刪除會員:表單(節錄) del. php … $sqlstr="select id from member where rank=1 and status =1"; $result=mysql_query($sqlstr, $link); ? > <h 1 align="center">選取要刪除的會員</h 1><p align="center"> <form name="form 1" action=del_chk. php method=post> <SELECT name="del_id" size="1"> <? while($row = mysql_fetch_array($result, MYSQL_BOTH)){ echo "<OPTION>". $row["id"]; } ? > </SELECT> <input type="submit" name="送出"><input type="reset" name="重設"></p> </form> …
管理者刪除會員:判斷(節錄) del_chk. php … if($_POST['del_id']==''){ my_msg("欄位不可空白", "del. php"); } $sqlstr="update member set status = 0 where id = '". $_POST['del_id']. "'"; //組合 sql $result=mysql_query($sqlstr, $link); //執行 sql …
管理者修改會員:表單(節錄) mod_passwd. php … $sqlstr="select id from member where rank=1 and status =1"; $result=mysql_query($sqlstr, $link); ? > <h 1 align="center">選取要變更密碼的會員</h 1><center> <form name="form 1" action=mod_passwd_chk. php method=post> <SELECT name="mod_id" size="1"> <? while($row = mysql_fetch_array($result, MYSQL_BOTH)){ echo "<OPTION>". $row["id"]; } ? > </SELECT></p> 請輸入這個會員的新密碼:<input type="password" name="passwd"></p> 請重複輸入這個會員的新密碼以確認:<input type="password" name="repasswd"></p> <input type="submit" name="送出"><input type="reset" name="重設"> </p> </form>
管理者修改會員資料:判斷(節錄) mod_passwd_chk. php … if($_POST['passwd']=='' or $_POST['repasswd']==''){ my_msg("欄位不可空白", "mod_passwd. php"); } if($_POST['passwd']!=$_POST['repasswd']){ my_msg("密碼並不相符,需重複鍵入相同密碼以確認 ", "mod_passwd. php"); } $sqlstr="update member set passwd ='". $_POST['passwd']. "' where id = '". $_POST['mod_id']. "'"; $result=mysql_query($sqlstr, $link); …
- Slides: 41