羅德興老師的教學歷程檔案 - 107-2 資料庫系統實作 - 期末作業展示 |
|
|
期末作業展示參考例 1 (平時作業):http://da.cust.edu.tw/abc/mydb/參考例 2 (期末專題):http://da.cust.edu.tw/abc/myshop/ 參考例 3:http://cc.cust.edu.tw/~dsluo/ Server:da.cust.edu.tw (Terminal 可以 WinSCP 連線處理) ID:abc PW:%abc123 MySQL database (可以 phpmyadmin 處理) ID:abc PW:%abc123 期末專題--訂單系統範例下載:感謝 志賢同學幫忙完成,請連結網址 https://drive.google.com/open?id=1acdU7pQX8PFsPLxNWPd_tJLWlJH-z84l 1. 操作資料庫 phpmyadmin 請使用 da.cust.edu.tw/phpmyadmin 2. config.php 請改用 <?php $host = "localhost"; $user = "abc"; $pwd = "%abc123"; $dbname="10514D006"; $conn=mysql_connect($host,$user,$pwd) or die(mysql_error()); mysql_select_db($dbname,$conn) or die(mysql_error()); mysql_query('SET NAMES utf8'); ?> 3. SQL 程式 請改用 -- DROP DATABASE IF EXISTS mydb000; CREATE DATABASE mydb000 DEFAULT CHARACTER SET utf8; USE mydb000; CREATE TABLE stmd ( intid INT(10) NOT NULL AUTO_INCREMENT COMMENT '遞增識別碼', depart_class CHAR(6) NOT NULL COMMENT '權限代碼', student_no CHAR(9) NOT NULL COMMENT '學號', student_name VARCHAR(20) NOT NULL COMMENT '姓名', address VARCHAR(60) NOT NULL COMMENT '地址', primary key(intid) ); LOAD DATA INFILE "/home/abc/www/1041AD000/imd2/stmd.txt" INTO TABLE stmd FIELDS TERMINATED BY ","; 4. text2.php 程式 請改用以下範例 <?php include "config.php"; if (isset($_POST["command"])) $command=$_POST["command"]; else $command=""; if ($command=="" || $command=="返回") { display_first_page($conn); } elseif ($command=="新增") { display_insert_page($conn); display_first_page($conn); } elseif ($command=="查詢") { display_search_page($conn); } elseif ($command=="更新") { display_modify_page($conn); } elseif ($command=="更新確認") { display_confirm_page($conn); display_first_page($conn); } elseif ($command=="刪除") { display_delete_page($conn); display_first_page($conn); } mysql_close($conn); function display_first_page($conn) { echo "<html><head><title>MySql與PHP結合-TEXT-新增-查詢-刪除-更新範例</title> <link rel='stylesheet' type='text/css' href='style.css'> </head><body><center> <table> <form method='post' action=''> <tr class='alt0'><td colspan=2>MySql與PHP結合-TEXT-新增-查詢-刪除-更新範例 By 1041AD000 羅同學 </td></tr> <tr><td class='alt1'>班級代碼</td> <td><input type='text' name='depart_class' size=10/></td></tr> <tr><td class='alt1'>學號</td> <td><input type='text' name='student_no' size=20 /></td></tr> <tr><td class='alt1'>姓名</td> <td><input type='text' name='student_name' size=20 /></td></tr> <tr><td class='alt1'>地址</td> <td><input type='text' name='address' size=60 /></td></tr> </table> <input class='cmd' type='submit' name='command' value='查詢'> <input class='cmd' type='submit' name='command' value='新增'> </form></center></body></html>"; } function display_search_page($conn) { $depart_class=$_POST["depart_class"]; if ($depart_class=="") $depart_class="%"; else $depart_class="%".$depart_class."%"; $student_no=trim($_POST["student_no"]); if ($student_no=="") $student_no="%"; else $student_no="%".$student_no."%"; $student_name=trim($_POST["student_name"]); if ($student_name=="") $student_name="%"; else $student_name="%".$student_name."%"; $address=trim($_POST["address"]); if ($address=="") $address="%"; else $address="%".$address."%"; $sql="select * from stmd where depart_class like '$depart_class' and student_no like '$student_no' and student_name like '$student_name' and address like '$address' order by depart_class,student_no"; $result=mysql_query($sql,$conn); echo "<html><head><title>MySql與PHP結合-TEXT-新增-查詢-刪除-更新範例</title> <link rel='stylesheet' type='text/css' href='style.css'> </head><body><center> <table><form method='post' action=''> <tr class='alt0'><td colspan=6>MySql與PHP結合-TEXT-新增-查詢-刪除-更新範例 By 1041AD000 羅同學</td></tr> <tr class='alt1'><td>班級代碼</td><td>學號</td><td>姓名</td> <td>地址</td><td>選擇</td></tr>"; $cnt=0; while ($myrow=mysql_fetch_array($result)) { $depart_class=$myrow["depart_class"]; $student_no=$myrow["student_no"]; $student_name=$myrow["student_name"]; $address=$myrow["address"]; $bgcolor=$cnt % 2+ 2; echo "<tr class='alt$bgcolor'><td>$depart_class</td><td>$student_no</td> <td>$student_name</td><td>$address</td> <td><input type='radio' name='student_no' value='$student_no'></td></tr>"; $cnt++; } echo "</table> <input class='cmd' type='submit' name='command' value='更新'> <input class='cmd' type='submit' name='command' value='刪除' onclick=\"return confirm('確定要刪除嗎');\" > <input class='cmd' type='submit' name='command' value='返回'> </form></center></body></html>"; } function display_insert_page($conn) { $depart_class=trim($_POST["depart_class"]); $student_no=trim($_POST["student_no"]); if ($student_no=="") { display_first_page($conn); exit(); } $student_name=trim($_POST["student_name"]); $address=trim($_POST["address"]); $sql="insert into stmd values(null,'$depart_class','$student_no','$student_name','$address')"; mysql_query($sql,$conn); } function display_modify_page($conn) { $student_no=$_POST["student_no"]; if ($student_no=="") { display_first_page($conn); exit(); } $sql="select * from stmd where student_no='$student_no' "; $result=mysql_query($sql,$conn); $myrow=mysql_fetch_array($result); $depart_class=$myrow["depart_class"]; $student_no=$myrow["student_no"]; $student_name=$myrow["student_name"]; $address=$myrow["address"]; echo "<html><head><title>MySql與PHP結合-TEXT-新增-查詢-刪除-更新範例</title> <link rel='stylesheet' type='text/css' href='style.css'> </head><body><center> <table><form method='post' action=''> <tr class='alt0'><td colspan=6>MySql與PHP結合-TEXT-新增-查詢-更新-刪除範例</td></tr> <table> <form method='post' action=''> <tr class='alt0'><td colspan=2>MySql與PHP結合-TEXT-RADIO-新增-查詢-範例</td></tr> <tr><td class='alt1'>班級代碼</td> <td><input type='text' name='depart_class' value='$depart_class' /></td></tr> <tr><td class='alt1'>學號</td> <td><input type='text' name='student_no' value='$student_no' readonly /></td></tr> <tr><td class='alt1'>姓名</td> <td><input type='text' name='student_name' value='$student_name' /></td></tr> <tr><td class='alt1'>地址</td> <td><input type='text' name='address' value='$address' /></td></tr> </table> <input class='cmd1' type='submit' name='command' value='更新確認' onclick=\"return confirm('確定要更新嗎');\" > <input class='cmd' type='submit' name='command' value='返回'> </form></center></body></html>"; } function display_delete_page($conn) { $student_no=$_POST["student_no"]; if ($student_no=="") { display_first_page($conn); exit(); } $sql="delete from stmd where student_no='$student_no'"; mysql_query($sql,$conn); } function display_confirm_page($conn) { $student_no=$_POST["student_no"]; $depart_class=$_POST["depart_class"]; $student_name=$_POST["student_name"]; $gender=$_POST["gender"]; $address=$_POST["address"]; $sql="update stmd set depart_class='$depart_class',student_name='$student_name', address='$address' where student_no='$student_no'"; mysql_query($sql,$conn); } ?>
|
|
中華科技大學數位化學習歷程 - 意見反應 |