Last active
December 29, 2015 13:59
-
-
Save ngnguyen1/7681375 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $conn = mysql_connect('localhost', 'root', ''); | |
| mysql_select_db('NhacTrucTuyen'); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DROP DATABASE IF EXISTS NhacTrucTuyen; | |
| CREATE DATABASE NhacTrucTuyen; | |
| USE NhacTrucTuyen; | |
| CREATE TABLE IF EXISTS tblCaKhuc ( | |
| maCK int PRIMARY KEY, | |
| tenCK varchar(30), | |
| nhacsi varchar(40), | |
| namST int, | |
| dongnhac varchar(30) | |
| ); | |
| INSERT INTO tblCaKhuc VALUES (1002, "neu la anh", "nguyen van a", 2013, "nhac tre"); | |
| INSERT INTO tblCaKhuc VALUES (2745, "Co gai mo đường", "Xuan giao", 2005, "nhac do"); | |
| INSERT INTO tblCaKhuc VALUES (7410, "Gọi đò", "Hồng Xuơng Long", 2007, "nhac trữ tình"); | |
| INSERT INTO tblCaKhuc VALUES (2930, "nắng ấm xa dần", "MTP", 2013, "nhac tre"); | |
| INSERT INTO tblCaKhuc VALUES (1508, "thu cuối", "Đang cập nhật", 2011, "nhac rap"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require 'connect.php'; | |
| if(isset($_GET['insert'])) { | |
| $maCK = $_REQUEST['maCK']; | |
| $tenCK = $_REQUEST['tenCK']; | |
| $nhacsi = $_REQUEST['nhacsi']; | |
| $namST = $_REQUEST['namST']; | |
| $dongnhac = $_REQUEST['dongnhac']; | |
| mysql_query('INSERT INTO tblCaKhuc VALUES (' | |
| .$maCK. ', "' | |
| .$tenCK. '", "' | |
| .$nhacsi. '", ' | |
| .$namST. ', "' | |
| .$dongnhac. '")'); | |
| if(mysql_affected_rows() > 0) | |
| echo "Nhap thanh cong"; | |
| else | |
| echo "nhap that bai"; | |
| } | |
| ?> | |
| <form method="POST" class = "insert" action="?insert"> | |
| <ul> | |
| <li> | |
| <label for="maCK">Mã Ca Khúc <label> | |
| <input type="text" name="maCK" id="maCK" class="cakhuc" /> | |
| </li> | |
| <li> | |
| <label for="tenCK">Tên Ca Khúc <label> | |
| <input type="text" name="tenCK" id="tenCK" class="cakhuc" /> | |
| </li> | |
| <li> | |
| <label for="nhacsi">Nhạc Sĩ <label> | |
| <input type="text" name="nhacsi" id="nhacsi" class="cakhuc" /> | |
| </li> | |
| <li> | |
| <label for="namST">Năm sáng tác <label> | |
| <input type="text" name="namST" id="namST" class="cakhuc" /> | |
| </li> | |
| <li> | |
| <label for="dongnhac">Dòng nhạc <label> | |
| <input type="text" name="dongnhac" id="dongnhac" class="cakhuc" /> | |
| </li> | |
| </ul> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require 'connect.db'; | |
| $result = mysql_query('SELECT * FROM tblCaKhuc'); // thực hiện câu lệnh truy vấn lấy tất cả bản ghi trong database | |
| ?> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"/> <!-- Hiển thị tiếng việt trên trình duyệt --> | |
| </head> | |
| <body> | |
| <h1>Danh sách các ca khúc</h1> | |
| <table> | |
| <thead> | |
| <tr> | |
| <th>SongID</th> | |
| <th>SongName</th> | |
| <th>Musician</th> | |
| <th>Year</th> | |
| <th>SongType</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <?php | |
| while ($set = mysql_fetch_array($result)) { // Lấy tất cả kết quả của câu lệnh truy vấn $result cho vào mảng $set | |
| echo "<tr> | |
| <td align='center'>" . $set['maCK'] . "</td> | |
| <td align='center'>" . $set['tenCK'] . "</td> | |
| <td align='center'>" . $set['nhacsi'] . "</td> | |
| <td align='center'>" . $set['namST'] . "</td> | |
| <td align='center'>" . $set['dongnhac'] ."</td> | |
| </tr>" | |
| } | |
| ?> | |
| </tbody> | |
| </table> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function validateEmail() { | |
| var email = document.forms["myForm"]["email"].value; | |
| var aK = email.indexOf("@"); // Xác định số kí tự trước @ tính từ trái sang | |
| var dauCham = email.lastIndexOf("."); // Xác định số kí tự đứng trước dấu chấm, nhưng là dấu chấm cuối cùng. | |
| // Nếu sai trả về -1 | |
| if (email == "") { | |
| alert("email khong duoc de trong"); | |
| return false; | |
| } else if ((aK < 1) || (dauCham < aK + 2) || (dauCham + 2 > email.length)) { | |
| alert("email dien khong chinh xac"); | |
| return false; | |
| } else | |
| return true; | |
| } | |
| function validateNumber() { | |
| var num = document.forms["myForm"]["dienthoai"].value; | |
| var kiemtraNum = isNaN(num); | |
| if (num == '') { | |
| alert ("so khong duoc de trong"); | |
| return false; | |
| } else if (kiemtraNum == true) { | |
| alert ("So dien thoai phai la so"); | |
| return false; | |
| } else | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment