 |
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
//กำหนดชื่อโฮสต์, username และ password
$link = mysql_connect("localhost","root","1234");
mysql_query("webdb");//เรียกใช้ฐานข้อมูลชื่อว่า webdb
$sql = "Select*From webq;"; //ดึงทุกเรคคอร์ดจากตาราง webq
$count = 0; //กำหนดจำนวนคำถามเริ่มต้นให้เท่ากับ 0
$result = mysql_query ($sql);
$dbarr = mysql_fetch_array($result);
{
$count++; //วนลูปเพื่อนับจำนวนคำถามที่มีอยู่ทั้งหมดในตาราง
}
$itemno = $count + 1; //เพิ่มจำนวนข้อคำถามขึ้นอีก 1
//เพิ่มหมายเลขข้อ,หัวข้อ,รายละเอียด,ชื่อผู้ตั้งกระทู้,0 ลงในตาราง webq
$sql = "Insert into webq Values($itemno,'$topic','$detail','$name',0);";
$result = mysql_query($sql);
if ($result)
{
echo "เพิ่มกระทู้ใหม่ลงสู่ฐานข้อมูล<p>";
mysql_close($link);
}
else
{
echo"ไม่สามารถเพิ่มกระทู้ใหม่ลงในฐานข้อมูลได้<p>";
}
echo"<a href=show_webq.php>แสดงกระทู้ทั้งหมด</a><br>";
echo"<a href=form_webq.php>กลับสู่หน้าฟอร์มตั้งกระทู้ใหม่</a><br>";
?>
</body>
</html>
Tag : PHP, MySQL, HTML/CSS
|
|
 |
 |
 |
 |
Date :
2011-07-13 14:49:32 |
By :
happyclub |
View :
760 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |