รบกวนหน่อยครับผมเพิ่งหัดเขียน php ติดต่อ Mysql อ่ะครับ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา รบกวนหน่อยครับผมเพิ่งหัดเขียน php ติดต่อ Mysql อ่ะครับ
รบกวนหน่อยครับผมเพิ่งหัดเขียน php ติดต่อ Mysql อ่ะครับ
พี่ครับ คือใน ฐานข้อมูลถ้าเป็น forn ไทยจะไม่แสดงเป็นภาษาไทยอ่ะครับ แต่หน้าเพจแสดงเป็นภาษาไทยน่ะครับ
ส่วนโค๊ดที่ใช้จัดการหน้าแอดมิน ที่ใช้บันทึกข้อมูล
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | <? include_once "connDB.php" ; ?> <? if ( $submit == "OK" ){ if ( $id1 == "" ){ $sql = "INSERT INTO tbl_admin set Auto_ID='" . $Auto_ID . "',Password='" . $Password . "',Gender='" . $Gender . "',Title_Name='" . $Title_Name . "',FirstName='" . $FirstName . "',LastName='" . $LastName . "',User_type='" . $User_type . "',Position='" . $Position . "',Department='" . $Department . "',Email='" . $Email . "',Tel='" . $Tel . "',Remark='" . $Remark . "'" ; mysql_query( $sql ); } else { $sql = "UPDATE tbl_admin set Password='" . $Password . "',Gender='" . $Gender . "',Title_Name='" . $Title_Name . "',FirstName='" . $FirstName . "',LastName='" . $LastName . "',User_type='" . $User_type . "',Position='" . $Position . "',Department='" . $Department . "',Email='" . $Email . "',Tel='" . $Tel . "',Remark='" . $Remark . " ' WHERE Auto_ID='" . $id1 . "'" ; mysql_query( $sql ); } } if ( $submit == "DEL" ){ $sql = "delete from tbl_admin where Auto_ID ='" . $id1 . "'" ; mysql_query( $sql ); } ?> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=windows-874" /> <title>PHP CODE FATHER 2009</title> <link href= "style/style.css" rel= "stylesheet" type= "text/css" /> </head> <body> <center> <div id= "container" > <div id= "header" > <div id= "header_left" ></div> <div id= "header_main" >ระบบจัดการข้อมูล tbl_admin</div> <div id= "header_right" ></div> </div> <div id= "content" ><br><br> <? if ( $submit == "" or $show == "OK" ){?> <center><form name= "form1" method= "post" action= "admin.php?show=OK&strSearch=Y" > <table width= "50%" > <tr> <td width= "36%" ><div align= "right" >ค้นหา :<select name= "Search2" > <option value= "Password" <? if ( $Search2 == "Password" ){ ?>selected<? }?>>Password</option> <option value= "Title_Name" <? if ( $Search2 == "Title_Name" ){ ?>selected<? }?>>Title_Name</option> <option value= "FirstName" <? if ( $Search2 == "FirstName" ){ ?>selected<? }?>>FirstName</option> <option value= "LastName" <? if ( $Search2 == "LastName" ){ ?>selected<? }?>>LastName</option> <option value= "Position" <? if ( $Search2 == "Position" ){ ?>selected<? }?>>Position</option> <option value= "Department" <? if ( $Search2 == "Department" ){ ?>selected<? }?>>Department</option> </select></div> </td> <td width= "64%" ><input name= "Search" type= "text" size= "20" value= "<? echo $Search?>" onFocus= "this.value = '';" > <input type= "submit" name= "submit" value= "Search" > </td> </tr> </table> </form></center> <? if (!isset( $start )){ $start = 0; $page =1; } $limit = '15' ; if ( $strSearch == "Y" ){ $Qtotal = mysql_query( "select * from tbl_admin Where " . $Search2 . " like '%" . $Search . "%' " ); } else { $Qtotal = mysql_query( "select * from tbl_admin" ); } $total = mysql_num_rows( $Qtotal ); if ( $strSearch == "Y" ){ $Query = mysql_query( "select * from tbl_admin Where " . $Search2 . " like '%" . $Search . "%' order by Auto_ID DESC LIMIT $start,$limit" ); } else { $Query = mysql_query( "select * from tbl_admin order by Auto_ID DESC LIMIT $start,$limit" ); } $totalp = mysql_num_rows( $Query ); $xx = $totalp + $start ; $yy = $start +1; echo "ข้อมูลที่ " . $yy . " ถึงข้อมูลที่ " . $xx ; printf( " | จากทั้งหมด %d รายการ " , $total ); printf( " | หน้าที่ %d <br />" , $page ); ?><br><br> <table width= "98%" > <tr bgcolor= "#999999" height= "40" onmouseover= "this.style.backgroundColor='#CCFFCC'" onmouseout= "this.style.backgroundColor=''" > <td ><strong>Password </strong></td> <td ><strong>Title_Name </strong></td> <td ><strong>FirstName </strong></td> <td ><strong>LastName </strong></td> <td ><strong>Position </strong></td> <td ><strong>Department </strong></td> <td width= "8%" ><a href= "admin.php?submit=Add&show=" ><center><img src= "style/images/add.png" border= "0" ></center></a></td> </tr> <? while ( $arr = mysql_fetch_array( $Query )){ $autoid = $arr [ 'Auto_ID' ]; $i ++; if ( $i %2==0){ $bg = "#CCCCCC" ; } else { $bg = "#FFFFFF" ; } ?> <tr bgcolor= "<? echo $bg?>" onmouseover= "this.style.backgroundColor='#CCFFCC'" onmouseout= "this.style.backgroundColor=''" valign= "top" > <td><? echo $arr [ 'Password' ] ?></td> <td><? echo $arr [ 'Title_Name' ] ?></td> <td><? echo $arr [ 'FirstName' ] ?></td> <td><? echo $arr [ 'LastName' ] ?></td> <td><? echo $arr [ 'Position' ] ?></td> <td><? echo $arr [ 'Department' ] ?></td> <td align= "right" > <a href= "admin.php?submit=DEL&show=OK&id1=<? echo $autoid;?>" OnClick= "return chkdel();" ><img src= "style/images/-.png" border= "0" ></a> <a href= "admin.php?submit=Edit&id1=<? echo $autoid;?>" ><img src= "style/images/Tools.png" border= "0" ></a> </td> </tr> <? }?> </table> <? }?> <? if ( $submit == "Add" ){?> <form action= "admin.php?submit=OK&show=OK&id1=" method= "post" onSubmit= "return Check_txt()" > <table width= "98%" > <tr> <td width= "30%" >Auto_ID</td> <td width= "70%" ><input name= "Auto_ID" id= "Auto_ID" type= "text" size= "50" ></td> </tr> <tr> <td width= "30%" >Password</td> <td width= "70%" ><input name= "Password" id= "Password" type= "text" size= "50" > * </td> </tr> <tr> <td width= "30%" >Gender</td> <td width= "70%" ><input name= "Gender" id= "Gender" type= "text" size= "50" ></td> </tr> <tr> <td width= "30%" >Title_Name</td> <td width= "70%" ><input name= "Title_Name" id= "Title_Name" type= "text" size= "50" > * </td> </tr> <tr> <td width= "30%" >FirstName</td> <td width= "70%" ><input name= "FirstName" id= "FirstName" type= "text" size= "50" > * </td> </tr> <tr> <td width= "30%" >LastName</td> <td width= "70%" ><input name= "LastName" id= "LastName" type= "text" size= "50" > * </td> </tr> <tr> <td width= "30%" >User_type</td> <td width= "70%" ><input name= "User_type" id= "User_type" type= "text" size= "50" ></td> </tr> <tr> <td width= "30%" >Position</td> <td width= "70%" ><input name= "Position" id= "Position" type= "text" size= "50" > * </td> </tr> <tr> <td width= "30%" >Department</td> <td width= "70%" ><input name= "Department" id= "Department" type= "text" size= "50" > * </td> </tr> <tr> <td width= "30%" >Email</td> <td width= "70%" ><input name= "Email" id= "Email" type= "text" size= "50" ></td> </tr> <tr> <td width= "30%" >Tel</td> <td width= "70%" ><input name= "Tel" id= "Tel" type= "text" size= "50" ></td> </tr> <tr> <td width= "30%" >Remark</td> <td width= "70%" ><input name= "Remark" id= "Remark" type= "text" size= "50" ></td> </tr> <tr height= "50" > <td></td> <td align= "left" valign= "middle" ><input type= "submit" name= "Submit" value= " บันทึก " > <input type= "reset" name= "Submit2" value= "ล้างข้อมูล" > <input type= "button" name= "Submit222" value= " ยกเลิก " onclick= "document.location.href='admin.php?show=OK'" ></td> </tr> </table> </form> <? }?> <? if ( $submit == "Edit" ){ $sql = "select * from tbl_admin where Auto_ID =" . $id1 . " " ; $tem = mysql_query( $sql ); $row3 =mysql_fetch_array( $tem ); ?> <form action= "admin.php?submit=OK&show=OK&id1=<? echo $id1?>" method= "post" onSubmit= "return Check_txt();" > <table width= "98%" > <tr> <td width= "30%" >Auto_ID</td> <td width= "70%" ><input name= "Auto_ID" id= "Auto_ID" type= "text" size= "50" value= "<? echo $row3['Auto_ID'] ?>" ></td> </tr> <tr> <td width= "30%" >Password</td> <td width= "70%" ><input name= "Password" id= "Password" type= "text" size= "50" value= "<? echo $row3['Password'] ?>" > * </td> </tr> <tr> <td width= "30%" >Gender</td> <td width= "70%" ><input name= "Gender" id= "Gender" type= "text" size= "50" value= "<? echo $row3['Gender'] ?>" ></td> </tr> <tr> <td width= "30%" >Title_Name</td> <td width= "70%" ><input name= "Title_Name" id= "Title_Name" type= "text" size= "50" value= "<? echo $row3['Title_Name'] ?>" > * </td> </tr> <tr> <td width= "30%" >FirstName</td> <td width= "70%" ><input name= "FirstName" id= "FirstName" type= "text" size= "50" value= "<? echo $row3['FirstName'] ?>" > * </td> </tr> <tr> <td width= "30%" >LastName</td> <td width= "70%" ><input name= "LastName" id= "LastName" type= "text" size= "50" value= "<? echo $row3['LastName'] ?>" > * </td> </tr> <tr> <td width= "30%" >User_type</td> <td width= "70%" ><input name= "User_type" id= "User_type" type= "text" size= "50" value= "<? echo $row3['User_type'] ?>" ></td> </tr> <tr> <td width= "30%" >Position</td> <td width= "70%" ><input name= "Position" id= "Position" type= "text" size= "50" value= "<? echo $row3['Position'] ?>" > * </td> </tr> <tr> <td width= "30%" >Department</td> <td width= "70%" ><input name= "Department" id= "Department" type= "text" size= "50" value= "<? echo $row3['Department'] ?>" > * </td> </tr> <tr> <td width= "30%" >Email</td> <td width= "70%" ><input name= "Email" id= "Email" type= "text" size= "50" value= "<? echo $row3['Email'] ?>" ></td> </tr> <tr> <td width= "30%" >Tel</td> <td width= "70%" ><input name= "Tel" id= "Tel" type= "text" size= "50" value= "<? echo $row3['Tel'] ?>" ></td> </tr> <tr> <td width= "30%" >Remark</td> <td width= "70%" ><input name= "Remark" id= "Remark" type= "text" size= "50" value= "<? echo $row3['Remark'] ?>" ></td> </tr> <tr height= "50" > <td></td> <td><input type= "submit" name= "Submit" value= " บันทึก " > <input type= "button" name= "Submit222" value= " ยกเลิก " onclick= "document.location.href='admin.php?show=OK'" ></td> </tr> </table> </form> โค๊ดจะอยู่หน้าเดียวกันทั้งหมดน่ะครับ |
ผมลองเปลี่ยน windows-874 ไปเป็น UTF-8 แต่พอเปลี่ยนหน้าเพจกลับไม่แสดงภาษาไทยครับ รบกวนหนอ่ยครับ

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1

ความคิดเห็นที่
2
ผมเปลี่ยนตามพี่ Ninenil แล้วน่ะครับ
ส่วนหน้าแสดงผมได้เปลี่ยนจากบรรทัดที่ 19 เป็น UTF-8 เรียบร้อยแล้วครับจะได้ผลตามรูปที่แนบมาครับ
จากรูปหลังจากแก้เป็น UTF-8 บรรทัดที่ 19 ตามโค๊ดด้านบนน่ะครับ
1 2 3 4 5 6 7 8 9 10 11 | <? // หน้านี้จะใช้ connect DB น่ะครับ $host = "localhost" ; $user = "root" ; $password = "415236" ; $database = "DB_position" ; $link = mysql_connect( $host , $user , $password ) or die (mysql_error()); mysql_select_db( $database ) or die (mysql_error()); mysql_query( "set character set utf8" ); //กำหนดค่า character set ที่จะใช้แสดงผล ?> |

ความคิดเห็นที่
3
mysql_query("set character set utf8");
เปลี่ยนเป็น
mysql_query("set character set tis620");
ถ้ายังไม่ได้ คงต้องไล่ดูองค์ประกอบอื่นๆ

ความคิดเห็นที่
4
ได้แล้วครับพี่ผมลืม ตอน save เลือก type เป็น UTF-8
ขอบคุณมากครับ พี่ NineniK

ขอบคุณทุกการสนับสนุน
![]()