หัวข้อ: error ที่ header("Location: main.php"); เริ่มหัวข้อโดย: teerapon ที่ 29 มกราคม 2010, 09:41:33 ผม ส่งมาทำงานใน page นี้ แล้วมัน error ที่ header มันเป็นที่อะไรครับ
<title>Babybear Ok</title><? $user=$_POST['user']; $pass=$_POST['pass']; if ($user=="admin" and $pass=="1234") { // ให้ user เท่ากับ admin ให้ pass เท่ากับ 1234 session_start(); session_register("sess_adminid"); //เป็นการเช็คว่ามีการlogin หรือไม่ ถ้่ามีการล็อกอินให้เข้าไปที่ หน้า main โดยเรียกหน้า mainมาใช้ $sess_adminid=session_id(); header("Location: main.php"); //เรียกหน้า main มาใช้ } else { echo "<H3>ERROR : Username Password ١ͧ</H3>"; // เป็นการแสดงว่า username password ไม่ถูกต้องค่ะ } ?> หัวข้อ: Re: error ที่ header("Location: main.php"); เริ่มหัวข้อโดย: Reality ที่ 29 มกราคม 2010, 09:50:32 Error ขึ้นว่าอะไรเหรอครับ
(ผมไม่มีความสามารถในการเดา Error นะครับ) ก็ว่าไปนั่น ปัญหานี้เกิดจากการที่มี output ก่อนที่มีการเซ็ต header ทางแก้ก็คือให้ท่านเอาการเช็ค header อะไรนั่นไปไว้บรรทัดบนสุดครับ หรือย้าย <title> มาไว้หลังแท๊ก header ก็ได้ครับ หัวข้อ: Re: error ที่ header("Location: main.php"); เริ่มหัวข้อโดย: mongther ที่ 29 มกราคม 2010, 09:53:01 ลองเปลี่ยนเป็นแบบนี้ดีไหมครับ
โค๊ด: <title>Babybear Ok</title><? หรือไม่ก็เอา <title>Babybear Ok</title> ออกน่าจะแก้ได้ครับ หัวข้อ: Re: error ที่ header("Location: main.php"); เริ่มหัวข้อโดย: Reality ที่ 29 มกราคม 2010, 09:55:53 ลองเปลี่ยนเป็นแบบนี้ดีไหมครับ ยังงี้ก็ยังติดอยู่ดีครับ (แท๊ก <title> มันแสดงผลออกมาก่อนเลย ก็ถือเป็น output แล้วครับ ..)โค๊ด: <title>Babybear Ok</title><? หรือไม่ก็เอา <title>Babybear Ok</title> ออกน่าจะแก้ได้ครับ โค๊ด: <? ผิดพลาดอย่างไรขออภัย :wanwan017: --- Edited: ท่านเงียบผมก็ไปนอนละ เสียเวลาขิงๆ หัวข้อ: Re: error ที่ header("Location: main.php"); เริ่มหัวข้อโดย: teerapon ที่ 29 มกราคม 2010, 10:11:14 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\famm\view2.php on line 117
แก้ยังไงครับ งง ครับ ช่วยทีครับ อ้างถึง <? include "connect.php"; // เรียกให้ connect.php ขึ้นมาเพื่อใช้ติดต่อฐานข้อมูล $connect = mysql_connect($host,$db_username,$db_password); //คำสั่งที่ใช้เชื่อมต่อฐานข้อมูล if(!$connect){ echo "ไม่สามารถติดต่อฐานข้อมูลได้"; exit(); } $sql = "select * from tb_product where type='25' "; // เลือกข้อมูลจากฐานข้อมูล tb_product โดย 25 คือ รูป หมีน่ารัก $dbquery = mysql_db_query($dbname, $sql); // สั่งให้ sql ทำงาน $cols = 3; //เป็นคำสั่งที่สั่งให้เรียงรูปที่ละ สาม $c = $cols; //กำหนดให้ c=cols ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]"> <html xmlns="[url]http://www.w3.org/1999/xhtml[/url]"><!-- InstanceBegin template="/Templates/tem.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Babybear Ok</title> <!-- InstanceEndEditable --> <style type="text/css"> <!-- body { margin-top: 0px; margin-bottom: 0px; background-image: url(pic/bg.jpg); } a:link { text-decoration: none; color: #CC33FF; } a:visited { text-decoration: none; color: #CC33FF; } a:hover { text-decoration: none; color: #CC33FF; } a:active { text-decoration: none; } .style11 {font-size: 16px; } --> </style> <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> </head> <body> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FDF8FC"> <tr> <td colspan="4"><img src="pic/Banner.jpg" width="800" height="200" /></td> </tr> <tr> <td height="19" colspan="4" bgcolor="#F9DCEE"><table width="805" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="21" height="34" background="pic/bg1.jpg"> </td> <td width="200" bgcolor="#FDF8FC"><div align="center"><img src="pic/ann55.gif" width="25" height="25" /><img src="pic/ann55.gif" width="25" height="25" /><img src="pic/ann55.gif" width="25" height="25" /><img src="pic/ann55.gif" width="25" height="25" /><img src="pic/ann55.gif" width="25" height="25" /><img src="pic/ann55.gif" width="25" height="25" /><img src="pic/ann55.gif" width="25" height="25" /></div></td> <td background="pic/12.jpg"><table width="550" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="80" background="pic/12.jpg"><div align="center" class="style11"><a href="index.php">หน้าหลัก</a></div></td> <td width="106" background="pic/12.jpg"><div align="center" class="style11"><a href="member/register.html">สมัครสมาชิก</a></div></td> <td width="92" background="pic/12.jpg"><div align="center" class="style11"><a href="member/index.html">เข้าสู่ระบบ</a></div></td> <td width="90" background="pic/12.jpg"><div align="center" class="style11"><a href="searchregister.html">ค้นหาข้อมูล</a></div></td> <td width="90" background="pic/12.jpg"> <div align="center" class="style11"><a href="saow_tuck.php">ติดต่อเรา</a> </div></td> <td width="92" background="pic/12.jpg"><div align="center" class="style11"><a href="login.php">ผู้ดูแลระบบ</a></div></td> </tr> </table></td> <td width="25" background="pic/bg3.jpg"> </td> </tr> </table></td> </tr> <tr> <td width="22" background="pic/bg2.jpg"> </td> <td width="200" valign="top"><table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="200"><img src="pic/manu.jpg" width="200" height="40" /></td> </tr> <tr> <td> <img src="pic/11.jpg" width="19" height="20" /><a href="view1.php"> ตุ๊กตาหมีน่ารัก</a></td> </tr> <tr> <td><img src="pic/11.jpg" width="19" height="20" /> <a href="view2.php">ตุ๊กตาหมีรับปริญญา</a></td> </tr> <tr> <td><img src="pic/11.jpg" width="19" height="20" /> <a href="view3.php"> ตุ๊กตาหมีนัดเรียน</a></td> </tr> <tr> <td><img src="pic/11.jpg" width="19" height="20" /> <a href="view4.php"> ตุ๊กตาหมีนักกีฬา</a></td> </tr> <tr> <td><img src="pic/11.jpg" width="19" height="20" /> <a href="view5.php"> ตุ๊กตาหมีแต่งงาน</a></td> </tr> <tr> <td><img src="pic/11.jpg" width="19" height="20" /> <a href="view6.php"> ตุ๊กตาหมีแพนด้า</a></td> </tr> <tr> <td><img src="pic/11.jpg" width="19" height="20" /> <a href="view7.php">ตุ๊กตาหมีชุดอาชีพ</a></td> </tr> <tr> <td><img src="pic/11.jpg" width="19" height="20" /> <a href="view8.php"> ตุ๊กตาหมีนานาชาติ</a></td> </tr> <tr> <td> </td> </tr> </table></td> <td width="557" valign="top"><table width="537" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><!-- InstanceBeginEditable name="EditRegion1" --> <table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td><tr> <td><table align="center"> <tr> <? while($result = mysql_fetch_array($dbquery)) { /------ตรงนี้ครับ บันทัด ทีี่่่่่่่่่่่่ 117 -------------------------------------------------------------------------- $c --; ?> <td width="150"> <center> <a href="view.php?id=<?php echo $result['id']; ?>"><img src= "pic/<? echo $result[pic];?>" width="130" height="150" /></a> <br /> <br /> <?=$result[name];?> </center></td> <? if($c == 0) { $c = $cols; ?> </tr> <tr> <td></tr></td> </tr> <? } } ?> <tr> <td></tr></td> </tr> </table></td> </tr> </td> </tr> </table> <!-- InstanceEndEditable --></td> </tr> </table> </td> <td width="26" background="pic/bg3.jpg"> </td> </tr> <tr> <td colspan="4"><img src="pic/bg1.jpg" width="800" height="40" /></td> </tr> </table> </body> <!-- InstanceEnd --></html> หัวข้อ: Re: error ที่ header("Location: main.php"); เริ่มหัวข้อโดย: woratana ที่ 29 มกราคม 2010, 10:19:51 เห็นโค้ดแล้วเพิ่งนึกได้ว่าสองวันก่อนกำลังเซ็งเรื่อง mysql_query มัน deprecated (พอดีไม่ได้อัพเดท XAMPP นาน แถมในโฮสต์ที่ใช้อยู่ก็ไม่ได้อัพตาม :P)
กลับมาที่คำถามนะครับ ค่อนข้างมั่นใจว่ามัน Error เพราะ SQL ที่เขียนไปมีอะไรผิดพลาดครับ เลยดึงข้อมูลไม่ได้ (เช่น ชื่อ column, table ผิด) สงสัยอย่างนึง อันนี้ไม่แน่ใจนะครับ เพราะหลัง ๆ ใช้แต่ class DB ช่วยจัดการฐานข้อมูลมากกว่าเขียน SQL สด ๆ $sql = "select * from tb_product where type='25' "; ต้องใส่ ; ปิดหลังคำสั่ง SQL (where type='25';) ด้วยไหมครับ? หัวข้อ: Re: error ที่ header("Location: main.php"); เริ่มหัวข้อโดย: Reality ที่ 29 มกราคม 2010, 17:00:53 ไม่ต้องครับ
ท่านหมายถึง $sql = "select * from tb_product where type='25';"; <-- ใช่ไหมครับ ตอบเลยว่าไม่ต้อง :wanwan019: |