ช่วยดูหน่อยว่าถูกไหมครับ

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><body bgcolor="#FFFFFF">
<form name="form1" method="post" action="search1.php">
<?
$host="localhost";
$username="root";
$pass_word="root";
$db="mydatabase";
$tb="mounth";
mysql_connect( $host,$username,$pass_word) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
// $charset = "set character_set_results=tis620";
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");
$charset = "set names UTF8";
mysql_query($charset) or die('Invalid query: ' . mysql_error());

 

$sql="Select * From $tb order by id asc";
$db_query=mysql_db_query($db,$sql);
$num_rows=mysql_num_rows($db_query); /* นับ Reccord ที่พบ */
?>

<select name="mounth">
<option>กรุณาเลือกเดือน</option>
<?
$a=0;
while($a < $num_rows)
{
$result = mysql_fetch_array($db_query);
$id=$result[id];
$title=$result[title];
$text_mounth=$result[text_mounth];
?>
<option value="<? echo $id;?>">
<? echo $title;?>
</option>
<?
$a++;
}
?>
</select>
<input type="submit" name="Submit" value="ตกลง">
<label>
<input name="reset" type="reset" id="reset" value="เคลียร์">
</label>
</form>
<hr>
<p>
  <?
$host="localhost";
$username="root";
$pass_word="root";
$db="mydatabase";
$tb="mounth";
mysql_connect( $host,$username,$pass_word) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");

$sql="select * from $tb where id=$mounth";
$db_query=mysql_db_query($db,$sql);

$result = mysql_fetch_array($db_query);
$image=$result[image];
$title=$result[title];
$text_mounth=$result[text_mounth];

echo "$title <br><br>$text_mounth<br>";


?>
</p>
<p>&nbsp;</p>
</body>
</html>

 


 

01 ก.พ. 2552 3 2,739

อะนะ จะรู้ไหมเนี่ย

ผมบอกเป็นครั้งที่ 100 แล้วว่า ตรวจสอบ MySQL ง่ายๆ แค่ลอง echo คำสั่ง sql ออกมา แล้วเอาไปทดสอบบน phpMyAdmin จะได้คำตอบที่ชัดเจนกว่า
#1

$sql="select * from $tb where id=$mounth";  ผิดตรงนี้ค่ะ
#2

ขอบคุณครับ ผมกะลังทำ project ครับ

#3
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^