|
 |
|
ช่วยดูโค้ดให้หน่อยครับ ว่ามันผิดตรงไหนครับทำไมบนเซฟเวอร์จำลองมันทำงานปกติแต่ของจริงทำงานผิดพลาด |
|
 |
|
|
 |
 |
|
ช่วยดูให้หน่อยครับบนเซฟจำลองเวลาพิมพ์ชื่อแล้วมันก็หาเจอปรกติแต่เวลาเอาขึ้นโฮสจริงคลิกไปไม่มีอะไรเกิดขึ้นเลยครับช่วยดูให้หน่อยครับ
ว่ามันผิดพลาดตรงไหนครับ
Code
<?php
$hostname = "localhost";
$user = "root";
$password = "1234";
$dbname = "eoffice";
$tblname = "i_student";
$field_search = "firstname";
mysql_connect($hostname, $user, $password) or die("ติดต่อฐานข้อมูลไม่ได้");
mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้");
?>
<!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=TIS-620" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
background-color: #42413C;
margin: 0;
padding: 0;
color: #000;
}
ul, ol, dl {
padding: 0;
margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
margin-top: 0;
padding-right: 15px;
padding-left: 15px;
}
a img {
border: none;
}
a:link {
color: #42413C;
text-decoration: underline;
}
a:visited {
color: #6E6C64;
text-decoration: underline;
}
a:hover, a:active, a:focus {
text-decoration: none;
}
.container {
width: 960px;
background-color: #FFF;
margin: 0 auto;
}
.header {
background-color: #ADB96E;
}
.sidebar1 {
float: left;
width: 180px;
background-color: #EADCAE;
padding-bottom: 10px;
}
.content {
padding: 10px 0;
width: 780px;
float: left;
text-align: center;
}
.content ul, .content ol {
padding: 0 15px 15px 40px;
}
ul.nav {
list-style: none;
border-top: 1px solid #666;
margin-bottom: 15px;
}
ul.nav li {
border-bottom: 1px solid #666;
}
ul.nav a, ul.nav a:visited {
padding: 5px 5px 5px 15px;
display: block;
width: 160px;
text-decoration: none;
background-color: #C6D580;
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus {
background-color: #ADB96E;
color: #FFF;
}
.footer {
padding: 10px 0;
background-color: #CCC49F;
position: relative;
clear: both;
}
.fltrt {
float: right;
margin-left: 8px;
}
.fltlft {
float: left;
margin-right: 8px;
}
.clearfloat {
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
-->
</style></head>
<body>
<div class="container">
<div class="header">
</div>
<div class="sidebar1">
<ul class="nav">
<li><a href="#"> หน้าแรก</a></li>
<li><a href="#">เข้าสู่ระบบ</a></li>
<li><a href="#">ติดต่อทีมงาน</a></li>
</ul>
<p> </p>
<!-- end .sidebar1 --></div>
<div class="content">
<form name="form1" method="post" action="list_user.php">
<center><table border="0" cellspacing="5" cellpadding="0">
<tr>
<td>ค้นหาข้อมูล : </td>
<td>
<input type="text" name="search">
</td>
<td>
<input type="submit" name="Submit" value="ค้นหา">
</td>
</tr>
</table></center>
</form>
<?php
$sql = "select * from $tblname where $field_search like '%$search%'";
mysql_query("SET NAMES TIS620");
mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client=tis620");
mysql_query("SET character_set_connection=tis620");
$dbquery = mysql_db_query($dbname, $sql);
$num_rows = mysql_num_rows($dbquery);
$i=0;
while ($i < $num_rows)
{
$result = mysql_fetch_array($dbquery);
$dname = $result[dname];
$firstname = $result[firstname];
$lastname = $result[lastname];
echo'<center><table>';
echo' <tr bgcolor=#99ffcc> ';
echo '<td bgcolor=#99ff00> '.$dname.' '. $firstname.'</td>';
echo '<td> '.$lastname.' </td>';
echo' </tr>';
echo' </table></center>';
$i++;
}
mysql_close();
echo' <h1> </h1>
</div>
<div class="footer">
<p>ระบบติดตามนักเรียนโรงเรียนสุวรรณวิจิตรวิทยา ตำบลกังแอน อำเภอปราสาท จังหวัดสุรินทร์</p>
</div>
</div>
</body>
</html>';
?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2012-09-02 14:11:17 |
By :
maisurin |
View :
994 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง echo บรรทัดนี้ออกมาดูครับ ว่า query ตามที่เราต้องการป่าว
Code (PHP)
$sql = "select * from $tblname where $field_search like '%$search%'";
echo $sql;
|
 |
 |
 |
 |
Date :
2012-09-02 14:15:23 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ออกมาแล้วครับ แต่งงทำไม appserv มันรันได้ปรกติครับ แล้วบนโฮสต์จริงมันกลับรันไม่ได้อ่ะครับทั้งที่คำสั่งเหมือนกัน
|
 |
 |
 |
 |
Date :
2012-09-02 14:41:57 |
By :
maisurin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แสดงว่าตัวแปร $search ไม่มีค่าส่งมาครับ คุณรับ-ส่งค่าของตัวแปร $search ยังไงครับ ลอง echo $search; ออกมาดูครับ
|
ประวัติการแก้ไข 2012-09-02 14:53:37
 |
 |
 |
 |
Date :
2012-09-02 14:51:11 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งั้นลองสคริปนี้ครับ ว่าได้ป่าว
Code (PHP)
<?php
$hostname = "localhost";
$user = "root";
$password = "1234";
$dbname = "eoffice";
$tblname = "i_student";
$field_search = "firstname";
mysql_connect($hostname, $user, $password) or die("ติดต่อฐานข้อมูลไม่ได้");
mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้");
// รับค่าที่ต้องการค้นหา//
$search = $_POST['search'];
?>
<!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=TIS-620" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
background-color: #42413C;
margin: 0;
padding: 0;
color: #000;
}
ul, ol, dl {
padding: 0;
margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
margin-top: 0;
padding-right: 15px;
padding-left: 15px;
}
a img {
border: none;
}
a:link {
color: #42413C;
text-decoration: underline;
}
a:visited {
color: #6E6C64;
text-decoration: underline;
}
a:hover, a:active, a:focus {
text-decoration: none;
}
.container {
width: 960px;
background-color: #FFF;
margin: 0 auto;
}
.header {
background-color: #ADB96E;
}
.sidebar1 {
float: left;
width: 180px;
background-color: #EADCAE;
padding-bottom: 10px;
}
.content {
padding: 10px 0;
width: 780px;
float: left;
text-align: center;
}
.content ul, .content ol {
padding: 0 15px 15px 40px;
}
ul.nav {
list-style: none;
border-top: 1px solid #666;
margin-bottom: 15px;
}
ul.nav li {
border-bottom: 1px solid #666;
}
ul.nav a, ul.nav a:visited {
padding: 5px 5px 5px 15px;
display: block;
width: 160px;
text-decoration: none;
background-color: #C6D580;
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus {
background-color: #ADB96E;
color: #FFF;
}
.footer {
padding: 10px 0;
background-color: #CCC49F;
position: relative;
clear: both;
}
.fltrt {
float: right;
margin-left: 8px;
}
.fltlft {
float: left;
margin-right: 8px;
}
.clearfloat {
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
-->
</style></head>
<body>
<div class="container">
<div class="header">
</div>
<div class="sidebar1">
<ul class="nav">
<li><a href="#"> หน้าแรก</a></li>
<li><a href="#">เข้าสู่ระบบ</a></li>
<li><a href="#">ติดต่อทีมงาน</a></li>
</ul>
<p> </p>
<!-- end .sidebar1 --></div>
<div class="content">
<form name="form1" method="post" action="">
<center><table border="0" cellspacing="5" cellpadding="0">
<tr>
<td>ค้นหาข้อมูล : </td>
<td>
<input type="text" name="search">
</td>
<td>
<input type="submit" name="Submit" value="ค้นหา">
</td>
</tr>
</table></center>
</form>
<?php
$sql = "select * from $tblname where $field_search like '%$search%'";
mysql_query("SET NAMES TIS620");
mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client=tis620");
mysql_query("SET character_set_connection=tis620");
$dbquery = mysql_db_query($dbname, $sql) or die(mysql_error());
$num_rows = mysql_num_rows($dbquery) or die(mysql_error());
if($num_rows>0)
{
while($result = mysql_fetch_array($dbquery)){
$dname = $result['dname'];
$firstname = $result['firstname'];
$lastname = $result['lastname'];
echo'<center><table>';
echo' <tr bgcolor=#99ffcc> ';
echo '<td bgcolor=#99ff00> '.$dname.' '. $firstname.'</td>';
echo '<td> '.$lastname.' </td>';
echo' </tr>';
echo' </table></center>';
}
} else {
echo 'ไม่มีข้อมูลที่คุณต้องการค้นหาค่ะ';
}
mysql_close();
?>
<h1> </h1>
</div>
<div class="footer">
<p>ระบบติดตามนักเรียนโรงเรียนสุวรรณวิจิตรวิทยา ตำบลกังแอน อำเภอปราสาท จังหวัดสุรินทร์</p>
</div>
</div>
</body>
</html>
|
 |
 |
 |
 |
Date :
2012-09-02 15:05:02 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับผม ขอบคุณครับ ได้ความรู้เพิ่มแล้วครับ
|
 |
 |
 |
 |
Date :
2012-09-02 15:09:59 |
By :
maisurin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอาไปทำความเข้าใจดูนะครับ ไม่ยากๆ ดูว่าต่างจากที่เราเขียนยังไงบ้าง เด๋วก็เก่งเอง สู้ๆครับ  
|
 |
 |
 |
 |
Date :
2012-09-02 15:11:48 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|