資料庫課程設計 PHP web實現
阿新 • • 發佈:2018-12-13
紀念一下自己寫的東西.. 都說很垃圾就是了
直接用XAMPP做的 菜鳥網上學的PHP和HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>學生資訊</title> </head> <style> body { background: rgba(12, 100, 129, 1) url('https://images2018.cnblogs.com/blog/1393985/201806/1393985-20180613124043614-112674236.jpg') fixed no-repeattest1; background-position: 50% 5%; background-size: cover; } </style> <body> <center> <br><br> <h2>學生資訊管理</h2> <a href="myindex.php">瀏覽學生</a> <a href="login.php">增刪學生</a> <hr> <br><br><br><br><br> <form action="search.php" method="post"> <input type="text" name = "fname"><br> <input type="radio" name = "vehicle" value="name">姓名<br> <input type="radio" name = "vehicle" value="num"checked="checked">學號<br> <input type="radio" name = "vehicle" value="course" checked="checked">課程<br> <input type="submit" value = "搜尋"> </form> </center> <br><br><br><br><br><br><br><br><br><br><br><br><br> </body> </html>
<!DOCTYPE html> <head> <meta charset = "UTF-8"> <title>學生資訊管理</title> </head> <style> body { background: rgba(12, 100, 129, 1) url('https://images2018.cnblogs.com/blog/1393985/201806/1393985-20180613124043614-112674236.jpg') fixed no-repeat; background-position: 50% 5%; background-size: cover; } </style> <body> <center> <h3>瀏覽學生資訊<h3> <table width = "800" border = "1"> <tr> <th>學號</th> <th>姓名</th> <th>課程1</th> <th>課程2</th> <th>課程3</th> <th>課程4</th> <th>課程5</th> </tr> <?php $dbhost = "localhost:3306"; $dbuser = "root"; $dbpass = ""; $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(!$conn) { die('Could not connect: ' . mysqli_error()); } mysqli_query($conn , "set names utf8"); mysqli_select_db($conn, 'demo'); $sql = "SELECT * FROM stu"; $retval = mysqli_query($conn, $sql); while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>{$row['學號']}</td> "; echo "<td>{$row['姓名']}</td> "; echo "<td>{$row['課程1']} </td> "; echo "<td>{$row['課程2']} </td> "; echo "<td>{$row['課程3']} </td> "; echo "<td>{$row['課程4']} </td> "; echo "<td>{$row['課程5']} </td> "; echo "</tr>"; } ?> </table> </center> <h3> <a href="test1.php">返回首頁</a> </h3> </body> </html>myindex
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>課程查詢</title> </head> <style> body { background: rgba(12, 100, 129, 1) url('https://images2018.cnblogs.com/blog/1393985/201806/1393985-20180613124043614-112674236.jpg') fixed no-repeat; background-position: 50% 5%; background-size: cover; } </style> <body> <center> <?php $dbhost = "localhost:3306"; $dbuser = "root"; $dbpass = ""; $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(!$conn) { die('Could not connect: ' . mysqli_error()); } mysqli_query($conn , "set names utf8"); mysqli_select_db($conn, 'demo'); $sqlll = $_POST["fname"]; $sqlcheck = $_POST["vehicle"]; echo "<br><br><br><br><br><br><br><br><br><br><br><br><br>"; if($sqlcheck === 'course') { echo "<table width = '400' border = '2'>"; echo "<tr>"; echo "<th>學號</th>"; echo "<th>姓名</th>"; echo "</tr>"; $sql = "SELECT `學號`, `姓名`, `課程1`, `課程2`, `課程3`, `課程4`, `課程5` FROM `stu` WHERE `課程1` LIKE '$sqlll'"; $retval = mysqli_query($conn, $sql); while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>{$row['學號']}</td> "; echo "<td>{$row['姓名']}</td> "; echo "</tr>"; } $sql = "SELECT `學號`, `姓名`, `課程1`, `課程2`, `課程3`, `課程4`, `課程5` FROM `stu` WHERE `課程2` LIKE '$sqlll'"; $retval = mysqli_query($conn, $sql); while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>{$row['學號']}</td> "; echo "<td>{$row['姓名']}</td> "; echo "</tr>"; } $sql = "SELECT `學號`, `姓名`, `課程1`, `課程2`, `課程3`, `課程4`, `課程5` FROM `stu` WHERE `課程3` LIKE '$sqlll'"; $retval = mysqli_query($conn, $sql); while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>{$row['學號']}</td> "; echo "<td>{$row['姓名']}</td> "; echo "</tr>"; } $sql = "SELECT `學號`, `姓名`, `課程1`, `課程2`, `課程3`, `課程4`, `課程5` FROM `stu` WHERE `課程4` LIKE '$sqlll'"; $retval = mysqli_query($conn, $sql); while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>{$row['學號']}</td> "; echo "<td>{$row['姓名']}</td> "; echo "</tr>"; } $sql = "SELECT `學號`, `姓名`, `課程1`, `課程2`, `課程3`, `課程4`, `課程5` FROM `stu` WHERE `課程5` LIKE '$sqlll'"; $retval = mysqli_query($conn, $sql); while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>{$row['學號']}</td> "; echo "<td>{$row['姓名']}</td> "; echo "</tr>"; } echo "</table>"; } else { if($sqlcheck === 'name') {$sql = "SELECT * FROM `stu` WHERE `姓名` LIKE '$sqlll'";} else {$sql = "SELECT * FROM `stu` WHERE `學號` LIKE '$sqlll'";} echo "<table width = '800' border = '1'>"; echo "<tr>"; echo "<th>學號</th>"; echo "<th>姓名</th>"; echo "<th>課程1</th>"; echo "<th>課程2</th>"; echo "<th>課程3</th>"; echo "<th>課程4</th>"; echo "<th>課程5</th>"; $retval = mysqli_query($conn, $sql); while($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) { echo "<tr>"; echo "<td>{$row['學號']}</td> "; echo "<td>{$row['姓名']}</td> "; echo "<td>{$row['課程1']} </td> "; echo "<td>{$row['課程2']} </td> "; echo "<td>{$row['課程3']} </td> "; echo "<td>{$row['課程4']} </td> "; echo "<td>{$row['課程5']} </td> "; echo "</tr>"; } echo "</table>"; } ?> </center> <h3> <a href="test1.php">返回首頁</a> </h3> </body> </html>search
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>新增學生</title> </head> <style> body { background: rgba(12, 100, 129, 1) url('https://images2018.cnblogs.com/blog/1393985/201806/1393985-20180613124043614-112674236.jpg') fixed no-repeat; background-position: 50% 5%; background-size: cover; } </style> <body> <?php $use = $_POST["user"]; $pass = $_POST["password"]; echo "<br><br><br><br><br><br><br><br><br><br>"; echo "<center>"; if($use === "admin" && $pass == "123") { echo "<h1>Welcome, lwq</h1>"; echo "<br>"; echo "<form action='addaction.php' method='post'>"; echo "<input type='text' name = 's1'>學號<br>"; echo "<input type='text' name = 's2'>姓名<br>"; echo "<input type='text' name = 's3'>課程1<br>"; echo "<input type='text' name = 's4'>課程2<br>"; echo "<input type='text' name = 's5'>課程3<br>"; echo "<input type='text' name = 's6'>課程4<br>"; echo "<input type='text' name = 's7'>課程5<br>"; echo "<input type='submit' value = '新增'>"; echo "</form>"; echo "<br><br><br>"; echo "<form action='delete.php' method='post'>"; echo "<input type='text' name = 'd1'>學號<br>"; echo "<input type='text' name = 'd2'>姓名<br>"; echo "<input type='submit' value = '刪除'>"; echo "</form>"; } else { echo "sorry, assess denied!!<br>"; header("Location:test1.php"); } echo "</center>"; ?> <h3> <a href="test1.php">返回首頁</a> </h3> </body> </html>add
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登陸</title> </head> <style> body { background: rgba(12, 100, 129, 1) url('https://images2018.cnblogs.com/blog/1393985/201806/1393985-20180613124043614-112674236.jpg') fixed no-repeat; background-position: 50% 5%; background-size: cover; } </style> <body> <br><br><br><br><br><br><br><br><br><br> <center> <form action="add.php" method="post"> 使用者: <input type="text" name="user"><br> 密碼: <input type="password" name="password"> <input type="submit" value = "登陸"> </form> </center> <h3> <a href="test1.php">返回首頁</a> </h3> </body> </html>login
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>新增學生</title> </head> <style> body { background: rgba(12, 100, 129, 1) url('https://images2018.cnblogs.com/blog/1393985/201806/1393985-20180613124043614-112674236.jpg') fixed no-repeat; background-position: 50% 5%; background-size: cover; } </style> <body> <br><br><br><br><br><br><br><br><br><br> <center> <?php $r1 = $_POST["s1"]; $r2 = $_POST["s2"]; $r3 = $_POST["s3"]; $r4 = $_POST["s4"]; $r5 = $_POST["s5"]; $r6 = $_POST["s6"]; $r7 = $_POST["s7"]; $dbhost = "localhost:3306"; $dbuser = "root"; $dbpass = ""; $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(!$conn) { die('Could not connect: ' . mysqli_error()); } mysqli_query($conn , "set names utf8"); mysqli_select_db($conn, 'demo'); $sql = "INSERT INTO `stu` (`學號`, `姓名`, `課程1`, `課程2`, `課程3`, `課程4`, `課程5`) VALUES ('$r1', '$r2', '$r3', '$r4', '$r5', '$r6', '$r7');"; $retval = mysqli_query($conn, $sql); echo "新增成功"; ?> </center> <h3> <a href="add.php">繼續新增</a> <a href="test1.php">返回首頁</a> </body> </html>addaction
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>學生資訊</title> </head> <style> body { background: rgba(12, 100, 129, 1) url('https://images2018.cnblogs.com/blog/1393985/201806/1393985-20180613124043614-112674236.jpg') fixed no-repeat; background-position: 50% 5%; background-size: cover; } </style> <body> <br><br><br><br><br><br><br><br><br><br> <center> <?php $t1 = $_POST["d1"]; $t2 = $_POST["d2"]; $dbhost = "localhost:3306"; $dbuser = "root"; $dbpass = ""; $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(!$conn) { die('Could not connect: ' . mysqli_error()); } mysqli_query($conn , "set names utf8"); mysqli_select_db($conn, 'demo'); $sql = "DELETE FROM `stu` WHERE 學號 = '$t1'"; $retval = mysqli_query($conn, $sql); $sql = "DELETE FROM `stu` WHERE 姓名 = '$t2'"; $retval = mysqli_query($conn, $sql); echo "刪除成功"; ?> </center> <h3> <a href="test1.php">返回首頁</a> </body> </html>delete