สอนวิธีการทำระบบขอเพลง มินิสคริป by HTMLThai.com

การใช้งาน
- ไฟล์หน้าแรกฟอร์มขอเพลงคือ index.php
- ไฟล์ฐานข้อมูลคือ resong.sql
- ไฟล์ดูรายการเพลง  admin.php

การติดตั้ง
1. สร้างฐานข้อมูลใหม่ชื่อ dbsong
2. ทำการ import ไฟล์ฐานข้อมูล resong.sql เข้าไป
3. แก้ไขตั้งค่าติดต่อฐานข้อมูลให้ถูกต้องที่ไฟล์ dbconfig.php


 


 

รายละเอียด

ไฟล์ index.php   ฟอร์มรับข้อมูล

โค้ด :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ระบบขอเพลง</title>
</head>

<body>
<form name="form1" method="post" action="song_submit.php">
  ชื่อผู้ขอ:
    <input name="name" type="text" id="name">
  <br>
  ชื่อเพลง:
  <input name="song" type="text" id="song">
  <br>
  ชื่อนักร้อง:
  <input name="singer" type="text" id="singer">
  <br>
   <input name="submit" type="submit" id="submit" value="ขอเพลง" >
</form>
</body>
</html>


ไฟล์ song_submit.php       ไฟล์คำสั่งส่งข้อมูลเข้าไปในฐานข้อมูล

โค้ด :

<?
include('dbconfig.php');

$name = $_POST['name'];
$song = $_POST['song'];
$singer = $_POST['singer'];

mysql_query('SET NAMES UTF8');
$htmlthai = mysql_query("INSERT INTO resong (name,song,singer) VALUES ('$name','$song','$singer')");

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ok</title>
</head>

<body>
<?
if($htmlthai)
{
echo "ขอเพลงเรียบร้อย";
}
else
{
echo "ไม่สามารถขอเพลงได้ในขณะนี้ˆ";
}

?>
</body>
</html>



ไฟล์ admin.php    ไฟล์แสดงรายการขอเพลง

โค้ด :

<?
include('dbconfig.php');

mysql_query('SET NAMES UTF8');
$htmlthai = mysql_query("SELECT * FROM resong ORDER BY id DESC LIMIT 10");

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>รายการขอเพลง</title>
</head>

<body>

<?
if($htmlthai)
{

while($array = mysql_fetch_array($htmlthai))
{

echo '<b>ลำดับการขอเพลง:</b>'.$array['id'].' <br /><b>เพลง:</b>'.$array['song'].' <br /> <b>ร้องโดย:</b>'.$array['singer'].' <br /> <b>ผู้ขอ:</b>'.$array['name'].' <br /><hr>';

}
}
else
{
echo "ไม่สามารถรายการขอเพลงได้ในขณะนี้ˆ";
}

?>
</body>
</html>


ไฟล์ dbconfig.php       ไฟล์ตั้งค่าในการติดต่อกับฐานข้อมูล

โค้ด :

<? 
// ตั้งค่าติดต่อกับฐานข้อมูล
$host = 'localhost';
$user = 'root';         // ผู้ใช้งานฐานข้อมูล
$pass = '123456';       // รหัสผ่านฐานข้อมูล
$con = mysql_connect( $host, $user, $pass);
mysql_select_db('dbsong');
?>


demo หน้าแรก : http://htmlthai.com/song/
demo รายการเพลง : http://htmlthai.com/song/admin.php
ดาวโหลดไฟล์ทั้งหมดในไฟล์แนบ

 

ที่มา :
โค้ดทำระบบขอเพลง - ระบบขอเพลง มินิสคริป by HTMLThai.com - http://htmlthai.com/index.php?topic=230.0

หน้าหลัก - http://theroomxat.ueuo.com

 


Free Web Hosting