รายละเอียดของการตอบ ::
ตอนนี้ผมพอจะทราบปัญหาของมันแล้วครับ
มันเป็นเรื่องของภาษาที่ใช้กระมัง
ผมไม่แน่ใจว่า เซ็ต ค่าตรงไหน
เริ่มจากของเดิมนะครับ
Code (PHP)
<?
session_start();
?>
<meta charset=utf-8 />
<?
include "../config.php";
if(empty($_SESSION['UCode']))
{
echo "กรุณาเข้าสู่ระบบด้วยครับ";
exit();
}
if(!empty($_SESSION['UType']))
{
if( $_SESSION['UType'] != "1"){
echo "สำหรับผู้ดูแลระบบเท่านั้นครับ !";
exit();
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
</head>
<body>
<?
include"../config.php";
$sql = "select * from zUser where UCode = '".$_SESSION['UCode']."' ";
$sqlquery = mysql_query($sql);
$sqlresult = mysql_fetch_array($sqlquery);
$sql2 = "select * from zUserType where UType = '".$_SESSION['UType']."' ";
$sqlquery2 = mysql_query($sql2);
$sqlresult2 = mysql_fetch_array($sqlquery2);
echo "ยินดีต้อนรับ ";
echo $sqlresult2['UTName'];
echo $sqlresult['UCode'];
?>
<br>
<a href="../Logout.php"><input type="button" value="ออกจากระบบ" /></a>
<a href="edit_profile.php">Edit</a><br>
</body>
</html>
สังเกตบรรทัด ที่ 31 ครับ
จะเป็น <?
แล้วผลที่ได้จะออกมาแบบนี้ครับ
แต่ถ้าผมเปลี่ยนเป็น
Code (PHP)
<?
session_start();
?>
<meta charset=utf-8 />
<?
include "../config.php";
if(empty($_SESSION['UCode']))
{
echo "กรุณาเข้าสู่ระบบด้วยครับ";
exit();
}
if(!empty($_SESSION['UType']))
{
if( $_SESSION['UType'] != "1"){
echo "สำหรับผู้ดูแลระบบเท่านั้นครับ !";
exit();
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin</title>
</head>
<body>
<?php
include"../config.php";
$sql = "select * from zUser where UCode = '".$_SESSION['UCode']."' ";
$sqlquery = mysql_query($sql);
$sqlresult = mysql_fetch_array($sqlquery);
$sql2 = "select * from zUserType where UType = '".$_SESSION['UType']."' ";
$sqlquery2 = mysql_query($sql2);
$sqlresult2 = mysql_fetch_array($sqlquery2);
echo "ยินดีต้อนรับ ";
echo $sqlresult2['UTName'];
echo $sqlresult['UCode'];
?>
<br>
<a href="../Logout.php"><input type="button" value="ออกจากระบบ" /></a>
<a href="edit_profile.php">Edit</a><br>
</body>
</html>
บรรทัดที่ 31 ครับ
<?php
ค่าที่ได้จะเป็น
เช่นเดียวกับ บรรทัดที่ 6 ครับ
หากไม่ใส่ php มันจะส่งค่ามาได้แล้วทำงานได้
หากผมใส่ php มันจะ error เหมือนครั้งแรกครับ ว่าค่าที่ส่งมาเป็น ค่าว่าง
ผมเลยเข้าใจว่า หากมี <?php การทำงานของ SESSION จะไม่ทำงาน
แต่ echo ภาษาไทย ทำงานครับ
พอจะทราบวิธีแก้ไขไหมครับ