|
|
|
ปัญหาคือแทรกรูปภาพ eregi_replace แล้วมันไม่แสดงในฐานข้อมูลค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<?
mysql_connect("localhost","root","1234");
mysql_select_db("mydatabase");
$Member = 0;
// ป้องกันการแทรก html กับ ละเครื่องหมาย ' "
$txtQuestion = htmlspecialchars($txtQuestion);
$txtDetails = htmlspecialchars($txtDetails);
$txtName = htmlspecialchars($txtName);
// ป้องกันคำหยาบ
$word = array("ashole","a s h o l e","a.s.h.o.l.e","bitch","b i t c h","b.i.t.c.h","shit","s h i t","s.h.i.t","fuck","dick","f u c k","d i c k","f.u.c.k","d.i.c.k","มึง","มึ ง","กู","ควย","ค ว ย","ค.ว.ย","ปี้","เหี้ย","เฮี้ย","ชาติหมา","ชาดหมา","ช า ด ห ม า","ช.า.ด.ห.ม.า","ช า ติ ห ม า","ช.า.ติ.ห.ม.า","ไอ้","สัดหมา","สัด","เย็ด","หี");
$ban = "<font color=red>***</font>";
for ($i=0 ; $i<sizeof($word) ; $i++) {
$txtQuestion = eregi_replace($word[$i],$ban,$txtQuestion);
$txtDetails = eregi_replace($word[$i],$ban,$txtDetails);
$txtName = eregi_replace($word[$i],$ban,$txtName);
}
// ตรวจสอบการแทรกรูปภาพ
$text = array(
":sad:",":red:", ":big:", ":ent:", ":shy:", ":sleepy:", ":sun:", ":sg:", ":embarass:",
":dead:", "", ":clown:", ":pukey:", "", "", ":smoke:", ":angry:", ":confused:", ":cry:",
"", ":yawn:", ":devil:", ":tongue:", ":alien:",":tasty:",":crazy:",":agree:",":disagree:",":bawling:",
":crap:",":crying1:",":dunce:",":error:","",":lookaroundb:",":laugh:",":pimp:",":spiny:",":wavey:",":smash:",":angry:",
":brain:",":phone:",":zip:",":download:",":beer:",":censore:",":nolove:",":cranium:");
$pic =array(
"frown.gif","redface.gif","biggrin.gif","blue.gif","shy.gif","sleepy.gif","sunglasses.gif", "supergrin.gif","embarass.gif",
"dead.gif","cool.gif","clown.gif","pukey.gif","eek.gif","sarcblink.gif","smokin.gif","reallymad.gif","confused.gif","crying.gif",
"lol.gif","yawn.gif","devil.gif","tongue.gif","aysmile.gif","tasty.gif","grazy.gif","agree.gif","disagree.gif","bawling.gif",
"crap.gif","crying1.gif","dunce.gif","error.gif","evil.gif","lookaroundb.gif","laugh.gif","pimp.gif","spiny.gif","wavey.gif","smash.gif","angry.gif",
"brain.gif","phone.gif","zip.gif","download.gif","beer.gif","censore.gif","nolove.gif","cranium.gif");
for ($a=0 ; $a<sizeof($txt) ; $a++) {
$txtDetails = eregi_replace($txt[$a],"<img src=\"pic/$pic[$a]\">",$txtDetails);
}
// ตรวจสอบว่า มีการป้อน url หรือ email มาหรือไม่ ถ้ามีให้ทำ link
$txtDetails = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])","<a href=\"\\1://\\2\\3\" target=\"\\2\\3\">\\1://\\2\\3</a>",$txtDetails);
$txtDetails = eregi_replace("([[:alnum:]]+)@([^[:space:]]*)([[:alnum:]])","<a href=mailto:\\1@\\2\\3>\\1@\\2\\3</a>",$txtDetails);
// ให้ขึ้นบันทัดใหม่ กรณีที่มีการเคาะ Enter
$txtDetails = eregi_replace(chr(13),"<br>",$txtDetails);
mysql_close();
// ปรับเวลาให้ตรงกับเวลาเมืองไทย กรณีที่ server อยู่ที่เมืองนอก
$mdate = date("j M Y H:i",mktime( date("H")+$p_hour, date("i")+$p_min ));
// เขียนข้อมูลลง database
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "INSERT INTO webboard ";
$strSQL .="(CreateDate,Question,Details,Name) ";
$strSQL .="VALUES ";
$strSQL .="('".date("Y-m-d H:i:s")."','".$_POST["txtQuestion"]."','".$_POST["txtDetails"]."','".$_POST["txtName"]."') ";
$objQuery = mysql_query($strSQL);
if($objQuery){
echo "<center>";
echo "<table width=60% border=1 bordercolor=#ff69b4 bgcolor=#f0ffff cellpadding=2 cellspacing=0>";
echo "<tr><td align=center>";
echo "<font size=2 face='MS Sans Serif'>";
echo "<font size=3 color=red><b>ได้รับข้อมูลแล้ว</b></font><br><br>";
echo "หากคำถามของคุณไม่ขึ้นให้กดปุ่ม Refresh/Reload ";
echo "</font></td></tr></table>";
echo "<br><hr color=FF1493 width=600>";
echo "<font size=2 face='MS Sans Serif'>";
echo "[ <a href='webboard.php'>กลับสู่กระดานสนทนาค่ะ</a> | ";
echo "<font>";
echo "</center>";
}
else {
echo "Error <br>";
}
?>
รบกวนดูโค้ดให้หน่อยค่ะ ทำยังไงก้อไม่ยอมขึ้นสักที
Tag : PHP
|
|
|
|
|
|
Date :
2012-10-13 17:47:51 |
By :
suthasinee10 |
View :
1022 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ได้แล้วค่ะ นั่งแก้เป็นวันๆ พอ search หาดูใน บอร์ด ก้อเจอของคุณ PlaKriM ให้ใช้
str_replace
ขอแชร์ให้กับคนที่กำลังเจอปัญหานี้นะค่ะ โค้ดอาจจะเยอะ รกๆ คนเก่งๆก้อไปปรับแก้เองนะจ๊ะ
ปกติเราจะเรียกดูข้อมูลจากฐานข้อมูล เช่น (อันนี้เป็นตัวอย่างแบบย่อๆ)
Code (PHP)
<tr>
<td height="53" colspan="2"><?= $objResult["Details"];?>
</td>
</tr>
แต่เราจะเพิ่มเป็นดังนี้ค่ะ
Code (PHP)
<tr>
<?
$txt = array(
":sad:",":red:", ":big:", ":ent:", ":shy:", ":sleepy:", ":sun:", ":sg:", ":embarass:",
":dead:", "", ":clown:", ":pukey:", "", "", ":smoke:", ":angry:", ":confused:", ":cry:",
"", ":yawn:", ":devil:", ":tongue:", ":alien:",":tasty:",":crazy:",":agree:",":disagree:",":bawling:",
":crap:",":crying1:",":dunce:",":error:","",":lookaroundb:",":laugh:",":pimp:",":spiny:",":wavey:",":smash:",":angry:",
":brain:",":phone:",":zip:",":download:",":beer:",":censore:",":nolove:",":cranium:");
$pic =array(
"<img src='pic/frown.gif'>","<img src='pic/redface.gif'>","<img src='pic/biggrin.gif'>","<img src='pic/blue.gif'>","<img src='pic/shy.gif'>","<img src='pic/sleepy.gif'>","<img src='pic/sunglasses.gif'>", "<img scr='pic/supergrin.gif'>","<img src='pic/embarass.gif'>",
"<img src='pic/dead.gif'>","<img src='pic/cool.gif'>","<img src='pic/clown.gif'>","<img src='pic/pukey.gif'>","<img src='pic/eek.gif'>","<img src='pic/sarcblink.gif'>","<img src='pic/smokin.gif'>","<img src='pic/reallymad.gif'>","<img src='pic/confused.gif'>","<img src='pic/crying.gif'>",
"<img src='pic/lol.gif'>","<img src='pic/yawn.gif'>","img src='pic/devil.gif'>","<img src='pic/tongue.gif'>","<img src='pic/aysmile.gif'>","<img src='pic/tasty.gif'>","<img src='pic/grazy.gif'>","<img src='pic/agree.gif'>","<img src='pic/disagree.gif'>","<img src='pic/bawling.gif'>",
"<img src='pic/crap.gif'>","<img src='pic/crying1.gif'>","<img src='pic/dunce.gif'>","<img src='pic/error.gif'>","<img src='pic.evil.gif'>","<img src='pic/lookaroundb.gif'>","<img src='pic/laugh.gif'>","<img src='pic/pimp.gif'>","<img src='pic/spiny.gif'>","<img src='pic/wavey.gif'>","<img src='pic/smash.gif'>","<img src='pic/angry.gif'>",
"<img src='pic/brain.gif'>","<img src='pic/phone.gif'>","<img src='pic/zip.gif'>","<img src='pic/download.gif'>","<img src='pic/beer.gif'>","<img src='pic/censore.gif'>","<img src='pic/nolove.gif'>","<img src='pic/cranium.gif'>");
for ($a=0 ; $a<sizeof($txt) ; $a++) {
$objResult["Details"] = str_replace($txt[$a],$pic[$a],$objResult["Details"]);
}
?>
<td height="53" colspan="2"><?= $objResult["Details"];?>
</td>
</tr>
|
|
|
|
|
Date :
2012-10-14 14:48:18 |
By :
suthasinee10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แจ๋ว
ถ้าจำไม่ผิดเค้าไม่ใช้ eregi_replace ตัวนี้แล้วใช่ป่าวน๊า
|
|
|
|
|
Date :
2012-10-14 19:54:21 |
By :
compiak |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|