|
 |
|
[เดือนร้อนมาก] ตัว ภ เป็นสี่เหลี่ยม อยู่ตัวเดียว แก้ไมได้สักทีคร้าบ |
|
 |
|
|
 |
 |
|
ใช้ phpmyadmin 2.10.3
ทำงานมาปกติครับ
แต่มาตายตรง ดึงข้อมูลมาแสดง ตัวที่เป็น ภ กลายเป็นสี่เหลี่ยมหมด
แก้มา 2 วันแล้ว หมดทางแล้วจริงๆ รบกวนช่วยดูให้หน่อยครับ
หน้า index (หัวข้อแสดงตัว ภ ได้ปกติ)
<?
$sql = "SELECT * FROM public where (status like 'ON')";
$result = mysql_query($sql, $conn);
echo "<center>";
echo "<table border=\"0\" cellpadding=\"2\" width =\"100%\">\n";
echo "<tr></tr>\n";
while($row = mysql_fetch_array($result))
{
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title={$row['title']}\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<td></td><td><div align=\"left\"><a href=\"show_pub.php?title={$row['title']}\">{$row['title']}</a></td>";
}
echo "</table>\n";
?>
หน้าแสดง detail (คลิกจากหัวข้อ) แสดงผลตัว ภ เป็นสี่เหลี่ยม
<?
$sql = "SELECT * FROM public where (title like '$title')";
$result = mysql_query($sql, $conn);
echo "<center>";
echo "<table border=\"0\" cellpadding=\"2\" width =\"100%\">\n";
echo "<tr></tr>\n";
while($row = mysql_fetch_array($result))
{
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title={$row['title']}\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<tr><td></td><td><div align=\"left\">{$row['title']}</a></td></tr>";
}
echo"<center>";
echo "<table border=\"0\" cellpadding=\"5\" width =\"80%\">\n";
echo "<tr><td><div align=\"center\">$title</div></td>";
echo "<tr><td><div align=\"left\">$message</td></div>";
echo "<tr><td>เมื่อวันที่ : $mdate</td></tr>";
echo "</table>";
echo "<p><a href=\"index.php\">กลับหน้าแรก</a></p>";
echo"</center>";
?>
[head]code add หัวข้อ head]
<?
$title =$_POST[title];
$message =$_POST[message];
$mdate=date("Y-m-d G:i:s");
if($title == "" or $message == "")
{
echo "<script>alert('กรุณากรอกข้อมูลให้ครบ');history.back(); </script>";
exit();
}
else
{
if($photo_type == "image/pjpeg" || $photo_type == "image/gif" || $photo_type == "image/x-png")
{
$path = "pub/"; //กำหนดที่เก็บรูปภาพใหม่
$width = 800; //กำหนดความกว้างของรูปใหม่
$height = 600; //กำหนดความสูงของรูปใหม่
if($photo_type == "image/pjpeg") $images_orig = ImageCreateFromJPEG($photo);
else if($photo_type == "image/gif") $images_orig = ImageCreateFromGIF($photo);
else if($photo_type == "image/x-png") $images_orig = ImageCreateFromPNG($photo);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
if($photo_type == "image/pjpeg") ImageJPEG($images_fin,$path.$photo_name);
else if($photo_type == "image/gif") ImageGIF($images_fin,$path.$photo_name);
else if($photo_type == "image/x-png") ImagePNG($images_fin,$path.$photo_name);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
$sql="INSERT INTO public (title,message,mdate,status,pubpic)VALUES ('$title','$message','$mdate','ON','$photo_name')";
if(mysql_query($sql,$conn)){
echo "<script>alert('เพิ่มข้อมูลได้แล้ว');history.back(); </script>";
echo "$message";
} else
{
echo "<script>alert('ไม่สามารถเพิ่มข้อมูลได้');history.back(); </script>";
}
}
}
?>



Tag : PHP, MySQL, CakePHP

|
|
 |
 |
 |
 |
Date :
2011-01-05 17:39:25 |
By :
kwakwan |
View :
1561 |
Reply :
22 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Connect
<?php
$host="localhost"; // ชื่อ host
$username="root"; // ชื่อที่เข้าใช้
$password="1234"; // รหัสเข้าใช้ระบบ
$db="thongphaphum"; // ชื่อฐานข้อมูล
$conn= mysql_connect($host,$username,$password) or die("don't connect mysql");
mysql_select_db($db);
mysql_query("set NAMES utf8");
?>
เคยลองเปลี่ยนเป็น tis620 หมดแล้วก็ไม่หายครับ
|
 |
 |
 |
 |
Date :
2011-01-05 17:48:07 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
น่าจะเป็นที่ Encode ของไฟล์็ไม่ตรงกับ อักขระที่บันทึกลงใน Database
ลอง Trobleshoot ดังนี้ดูครับ
1. Database : format utf-8 หรือปล่าว
2. ไฟล์โปรแกรมตอน Save เลือก Type เป็น utf-8 หรือปล่าว
3. Header metatag เป็น UTF-8 หรือปล่าว
แต่เห็นใช้ dream เวลาเรา save ปกติมันจะบันทึก format เป็น iso889 xxx ครับถ้ามีพิมพ์ไทยไปด้วย แต่ถ้า database คุณเก็บ format อีกแบบ เวลา translation เอกสารมันจะยึดตามไฟล์ที่คุณ save ถึงแม้จะใส่ metatag ในเอกสารเพื่อบังคับการแสดงผลแล้วก็ตามก็ยังยึกยืออยู่ดี
ลอง copy code ใส่ nodepad แล้ว save ไปใหม่แต่ก่อน save เลือก Type ของเอกสาร ให้ตรงกับ Database ที่เก็บครับ
|
 |
 |
 |
 |
Date :
2011-01-05 20:01:36 |
By :
mandy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอาโค้ดนี้ไปรันดูครับ
แล้วเอาหน้า Structure database มาดูหน่อยครับ ว่าเซ็ต collationเป็นอะไร
<!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>Detail</title>
</head>
<body>
<?php
$sql = "SELECT * FROM public where (title like '$title')";
$result = mysql_query($sql, $conn);
echo "<center>";
echo "<table border=\"0\" cellpadding=\"2\" width =\"100%\">\n";
echo "<tr></tr>\n";
while($row = mysql_fetch_array($result))
{
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title={$row['title']}\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<tr><td></td><td><div align=\"left\">{$row['title']}</a></td></tr>";
}
echo"<center>";
echo "<table border=\"0\" cellpadding=\"5\" width =\"80%\">\n";
echo "<tr><td><div align=\"center\">$title</div></td>";
echo "<tr><td><div align=\"left\">$message</td></div>";
echo "<tr><td>เมื่อวันที่ : $mdate</td></tr>";
echo "</table>";
echo "<p><a href=\"index.php\">กลับหน้าแรก</a></p>";
echo"</center>";
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2011-01-05 20:04:31 |
By :
DS_Ohm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|


เป็น unicode ทั้งหมดเลยครับ
|
 |
 |
 |
 |
Date :
2011-01-06 09:18:12 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ
แต่ code ของคุณ OHM ยังไม่หายอะครับ
|
 |
 |
 |
 |
Date :
2011-01-06 09:26:10 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เคยมีปัญหากับตัว ภ เหมือนกันครับ แต่สาเหตุคนละอย่างกันนะ ของผมมาจากพยามตัดข้อความ
สำหรับปัญหาของคุณ kwakwan
ผมสังเกตที่ querystring นะครับ title=admin%20ภภภภภ เอาตัวนี้มาแสดงแล้วเป็นสีเหลี่ยมเปล่า
ให้ทำการ encode url ก่อนครับ
<a href="show_pub.php?title=admin ภภภภภ">จะเป็นสีี่เหลี่ยม</a> ลองทดสอบดูครับจะเป็นสีเหลี่ยม
<a href="show_pub.php?title=<?=urlencode("admin ภภภภภ")?>">แสดงถูกต้อง</a> ลองลิงค์นี้ดูจะแก้ไขสี่เหลี่ยมได้
|
 |
 |
 |
 |
Date :
2011-01-06 09:34:07 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณใช้ tis-620 ใช่ป่ะ ลอง ใส่
header('Content-Type: text/html; charset=TIS-620');
|
 |
 |
 |
 |
Date :
2011-01-06 09:57:21 |
By :
pjgunner.com |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมใช้เป็น UNICODE นะครับ
แต่ลองเปลี่ยนเป็น TIS 620 แล้วทั้งหมด ก็ยังไม่หายครับ
|
 |
 |
 |
 |
Date :
2011-01-06 10:09:51 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
index.php
<?
$sql = "SELECT * FROM public where (status like 'ON')";
$result = mysql_query($sql, $conn);
echo "<center>";
echo "<table border=\"0\" cellpadding=\"2\" width =\"80%\">\n";
echo "<tr></tr>\n";
while($row = mysql_fetch_array($result))
{
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title=<?=urlencode({$row['title']})?>\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<td></td><td><div align=\"left\"><a href=\"show_pub.php?title={$row['title']}\">{$row['title']}</a></td>";
}
echo "</table>\n";
?>
ลองแก้ใน index.php แล้วตรง "><a href=\"show_pub.php?title=<?=urlencode({$row['title']})?>\"> ตามคุณ xbeginer01 ก็ยังไม่หายเลยครับ -0-
|
 |
 |
 |
 |
Date :
2011-01-06 10:18:34 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title=<?=urlencode({$row['title']})?>\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<td></td><td><div align=\"left\"><a href=\"show_pub.php?title={$row['title']}\">{$row['title']}</a></td>";
เขียนผิดแล้วครับ urlencode เป็นฟังก์ชันครับเขียนแบบนี้ไม่ได้ ถ้าจะเขียนอยู่ในรูป echo ต้องแก้วิธีเขียนใหม่
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title=".urlencode({$row['title']})."\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<td></td><td><div align=\"left\"><a href=\"show_pub.php?title={$row['title']}\">{$row['title']}</a></td>";
|
 |
 |
 |
 |
Date :
2011-01-06 10:25:26 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Unicode นี่ หมายถึง UTF-8 หรือป่าว หรือ อันอื่น ให้เซฟไฟล์ หรือคอนเวิดเป็น ตาม db ครับ
ถ้าหากคุณใช้ tis620 ผมเคยเจออยู่ที่ว่า ภ เป็น สี่เหลี่ยม คือตอนนั้น เรียกผ่าน ajax เลยเจอ
|
 |
 |
 |
 |
Date :
2011-01-06 10:26:16 |
By :
pjgunner.com |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?
$sql = "SELECT * FROM public where (status like 'ON')";
$result = mysql_query($sql, $conn);
echo "<center>";
echo "<table border=\"0\" cellpadding=\"2\" width =\"80%\">\n";
echo "<tr></tr>\n";
while($row = mysql_fetch_array($result))
{
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title=\".urlencode({$row['title']}).\"\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<td></td><td><div align=\"left\"><a href=\"show_pub.php?title={$row['title']}\">{$row['title']}</a></td>";
}
echo "</table>\n";
?>
ขอบคุณสำหรับคำแนะนำ จากคุณ xbeginer01 นะครับ
แต่มันยังไม่หายเลยอะครับ -_-"
|
 |
 |
 |
 |
Date :
2011-01-06 10:46:26 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนเป็น
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
|
 |
 |
 |
 |
Date :
2011-01-06 10:50:13 |
By :
lightkung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title=\".urlencode({$row['title']}).\"\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<td></td><td><div align=\"left\"><a href=\"show_pub.php?title={$row['title']}\">{$row['title']}</a></td>";
อ่ะก็ยังเขียนผิดอยู่ครับ
title=\".urlencode({$row['title']}).\" ไม่มี slash เอางี้ประกาศตัวแปรใหม่เลยละกัน
Code (PHP)
<?
$sql = "SELECT * FROM public where (status like 'ON')";
$result = mysql_query($sql, $conn);
echo "<center>";
echo "<table border=\"0\" cellpadding=\"2\" width =\"80%\">\n";
echo "<tr></tr>\n";
while($row = mysql_fetch_array($result))
{
$queryString=urlencode({$row['title']});
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title=$queryString\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<td></td><td><div align=\"left\"><a href=\"show_pub.php?title=$queryString\">{$row['title']}</a></td>";
}
echo "</table>\n";
?>
|
ประวัติการแก้ไข 2011-01-06 10:59:46
 |
 |
 |
 |
Date :
2011-01-06 10:58:11 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Parse error: syntax error, unexpected '{', expecting ')' in C:\AppServ\www\Thongphaphum\index.php on line 46
error syntax line นี้อะครับ
Code (PHP)
$queryString=urlencode({$row['title']});
|
 |
 |
 |
 |
Date :
2011-01-06 11:02:37 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
index
<?
$sql = "SELECT * FROM public where (status like 'ON')";
$result = mysql_query($sql, $conn);
echo "<center>";
echo "<table border=\"0\" cellpadding=\"2\" width =\"80%\">\n";
echo "<tr></tr>\n";
while($row = mysql_fetch_array($result))
{
$queryString=urlencode($row['title']);
echo "<tr> <td width=\"150\"><a href=\"show_pub.php?title=$queryString\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<td></td><td><div align=\"left\"><a href=\"show_pub.php?title={$row['title']}\">{$row['title']}</a></td>";
}
echo "</table>\n";
?>
show_pub
<?
$sql = "SELECT * FROM public where (title like '$title')";
$result = mysql_query($sql, $conn);
echo "<center>";
while($row = mysql_fetch_array($result))
{
echo "<br>";
echo "<img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"450\" height=\"300\" title='{$objResult['picname']}'>";
echo "<br>";
echo "<br>";
echo "{$row['title']}";
echo "<br>";
echo "<br>";
echo "<tr>{$row['message']}";
echo "<br>";
echo "<br>";
echo "<br>";
echo "เมื่อวันที่ : {$row['mdate']}";
}
echo"<center>";
echo "<p><a href=\"index.php\">กลับหน้าแรก</a></p>";
echo"</center>";
?>



|
 |
 |
 |
 |
Date :
2011-01-06 11:32:20 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ code ของคุณ xbeginer01 แล้ว ยังเป็นเหมือนเดิมเลยอะครับ
ติด ภ -0-
|
 |
 |
 |
 |
Date :
2011-01-06 11:33:26 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เด่วจะยาวครับ แอดผมมาดีกว่า [email protected] มีอยู่สองสามจุดเองครับ
|
 |
 |
 |
 |
Date :
2011-01-06 12:22:24 |
By :
xbeginner01 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แอดแล้วนะครับ
ขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2011-01-06 13:02:14 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Index.php
<?
$sql = "SELECT * FROM public where (status like 'ON')";
$result = mysql_query($sql, $conn);
echo "<center>";
echo "<table border=\"0\" cellpadding=\"2\" width =\"80%\">\n";
echo "<tr></tr>\n";
while($row = mysql_fetch_array($result))
{
$queryString=urlencode($row['title']);
echo "<tr> <td width=\"150\"> <a href=\"show_pub.php?title=$queryString\"> <img border=\"2\" src=\"pub/{$row['pubpic']}\" width=\"150\" height=\"100\" title='{$objResult['picname']}'></td>
<td></td><td><div align=\"left\"> <a href=\"show_pub.php?title=$queryString\">{$row['title']}</a></td>";
}
echo "</table>\n";
?>
พี่บี (xbeginer01) ช่วยแก้ให้แล้วครับ ตามโค้ดด้านบน
ขอบคุณพี่บีมากครับ
|
 |
 |
 |
 |
Date :
2011-01-06 14:46:12 |
By :
kwakwan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
mysql_query("SET NAMES 'utf8'");
ลอง ใช้นี่ ตรง config ดูครับ
น่าจะได้ เลย
|
 |
 |
 |
 |
Date :
2011-10-23 14:38:13 |
By :
ttt |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|