Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ช่วยที่ครับติดมาหลายวันล่ะ



 

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ช่วยที่ครับติดมาหลายวันล่ะ

 



Topic : 109392



โพสกระทู้ ( 16 )
บทความ ( 0 )



สถานะออฟไลน์




นี้โค๊ดทั้งหมดครับ ผมทำสีแดงไวแล้วครับอยู่แถวๆด้านล่าง แก้ให้หน่อยครับ ขอบคุณครับ


Code
<?php //message-outbox.php $fromuser = $_SESSION['username']; $sql = mysql_query("SELECT * FROM privatemessages WHERE fromuser = '$fromuser' AND outdel = '0' ORDER BY datesent DESC"); ?> <!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=utf-8" /> <title>Private Message Outbox</title> <meta name="description" content="Private Message Outbox — Sent Messages"> <meta name="keywords" content="Private Message Outbox,Sent Messages,Private Messaging,Private Message,php,javascript, dhtml, DHTML"> <script language="javascript"> mactest=(navigator.userAgent.indexOf("Mac")!=-1) //My browser sniffers Netscape=(navigator.appName.indexOf("Netscape") != -1) msafari=(navigator.userAgent.indexOf("Safari")!= -1) wsafari=0; if(!mactest&&msafari){wsafari=1;msafari=0} is_opera = 0; if(window.opera){is_opera=1} is_ie_mac = 0; is_ie=0;if(document.all){is_ie=1} function fixwidth(){if(Netscape||is_opera){e=document.getElementById('box');e.style.width='826px';e=document.getElementById('menu');e.style.width='116px';}} function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit){field.value = field.value.substring(0, maxlimit);} else{countfield.value = maxlimit - field.value.length;}} </script> <STYLE TYPE="text/css"> BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-color:#ccc} p, li {font:13px Verdana; color:black;text-align:left} h1 {font:bold 28px Verdana; color:black;text-align:center} h2 {font:bold 24px Verdana;text-align:center} h3 {font:bold 15px Verdana;} #box {background-color:#eee;position:absolute;top:50px;left:150px; width:850px;padding:10px;border:2px solid blue} #table1 {width:100%;border:1px solid blue;text-align:center} #menu {background-color:#eee;position:absolute;top:50px;left:0px; width:130px;padding:5px;border:2px solid blue} </STYLE> </head> <body onload="fixwidth()"> <h1>Private Message Outbox — Sent Messages</h1> <div id='menu'> <a HREF="send-message-form.php">Send Message</a><BR><BR> <a HREF="message-inbox.php">Message Inbox</a><BR><BR> <a HREF="message-outbox.php">Message Outbox</a><BR><BR> <a HREF="message-delete-received.php">Delete Inbox<BR>Message</a><BR><BR> <a HREF="message-delete-sent.php">Delete Outbox<BR>Message</a><BR><BR> <a HREF="message-login.php">Login</a><BR><BR> <a HREF="message-logout.php">Logout</a> </div> <div id='box'> <table id='table1' border='1'> <caption><b>Messages from: <?php echo $fromuser; ?></b></caption> <tr><th>To</th><th>Subject</th><th>Date</th> <th>Message</th></tr> <?php while($rows=mysql_fetch_array($sql)){ $sent=stripslashes($rows['datesent']); echo "<tr><td>".htmlentities(stripslashes($rows['touser']), ENT_QUOTES)."</td>"; echo "<td>".htmlentities(stripslashes($rows['subject']), ENT_QUOTES)."</td>"; echo "<td>".date('Y/m/d',$sent)."</td>"; echo "<td>".htmlentities(stripslashes($rows['message']), ENT_QUOTES)."</td></tr>";} mysql_close(); ?> </table> </body> </html>




Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-06-22 17:36:06 By : reatilink View : 813 Reply : 5
 

 

No. 1



โพสกระทู้ ( 9,542 )
บทความ ( 2 )



สถานะออฟไลน์


$sql = mysql_query("SELECT * FROM privatemessages WHERE fromuser = '$fromuser' AND outdel = '0' ORDER BY
datesent DESC");

?>


แก้เป็น
Code (PHP)
$sql = mysql_query($qr_chk="SELECT * FROM privatemessages WHERE fromuser = '$fromuser' AND outdel = '0' ORDER BY 
datesent DESC");
// ใส่ $qr_chk= ก่อน statement และ แทรก บันทัดล่างเพื่อเช็ค error
if(mysql_errno()){
     echo $qr_chk, "<br />'n", mysql_error(); exit;
}
?>









ประวัติการแก้ไข
2014-06-22 17:46:03
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-22 17:45:34 By : Chaidhanan
 


 

No. 2



โพสกระทู้ ( 16 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณครับพี่ Chaidhanan

มีอักอันหนึ่งครับ ขึ้นแบบนี้ mysql_fetch_array(): supplied argument is not a valid MySQL result resource in บรรทัดที่ 44
ขอบคุณมากครับ ((:

Code (PHP)
<?php
include('config.php');
?>
<!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=utf-8" />
        <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
        <title>New PM</title>
    </head>
    <body>
    	<div class="header">
        	<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Members Area" /></a>
	    </div>
<?php
//We check if the user is logged
if(isset($_SESSION['username']))
{
$form = true;
$otitle = '';
$orecip = '';
$omessage = '';
//We check if the form has been sent
if(isset($_POST['title'], $_POST['recip'], $_POST['message']))
{
	$otitle = $_POST['title'];
	$orecip = $_POST['recip'];
	$omessage = $_POST['message'];
	//We remove slashes depending on the configuration
	if(get_magic_quotes_gpc())
	{
		$otitle = stripslashes($otitle);
		$orecip = stripslashes($orecip);
		$omessage = stripslashes($omessage);
	}
	//We check if all the fields are filled
	if($_POST['title']!='' and $_POST['recip']!='' and $_POST['message']!='')
	{
		//We protect the variables
		$title = mysql_real_escape_string($otitle);
		$recip = mysql_real_escape_string($orecip);
		$message = mysql_real_escape_string(nl2br(htmlentities($omessage, ENT_QUOTES, 'UTF-8')));
		//We check if the recipient exists
		$dn1 = mysql_fetch_array(mysql_query('select count(id) as recip, id as recipid, (select count(*) from pm) as npm from users where username="'.$recip.'"'));
		if($dn1['recip']==1)
		{
			//We check if the recipient is not the actual user
			if($dn1['recipid']!=$_SESSION['userid'])
			{
				$id = $dn1['npm']+1;
				//We send the message
				if(mysql_query('insert into pm (id, id2, title, user1, user2, message, timestamp, user1read, user2read)values("'.$id.'", "1", "'.$title.'", "'.$_SESSION['userid'].'", "'.$dn1['recipid'].'", "'.$message.'", "'.time().'", "yes", "no")'))
				{
?>
<div class="message">The message has successfully been sent.<br />
<a href="list_pm.php">List of my personnal messages</a></div>
<?php
					$form = false;
				}
				else
				{
					//Otherwise, we say that an error occured
					$error = 'An error occurred while sending the message';
				}
			}
			else
			{
				//Otherwise, we say the user cannot send a message to himself
				$error = 'You cannot send a message to yourself.';
			}
		}
		else
		{
			//Otherwise, we say the recipient does not exists
			$error = 'The recipient does not exists.';
		}
	}
	else
	{
		//Otherwise, we say a field is empty
		$error = 'A field is empty. Please fill of the fields.';
	}
}
elseif(isset($_GET['recip']))
{
	//We get the username for the recipient if available
	$orecip = $_GET['recip'];
}
if($form)
{
//We display a message if necessary
if(isset($error))
{
	echo '<div class="message">'.$error.'</div>';
}
//We display the form
?>
<div class="content">
	<h1>New Personnal Message</h1>
    <form action="new_pm.php" method="post">
		Please fill the following form to send a personnal message.<br />
        <label for="title">Title</label><input type="text" value="<?php echo htmlentities($otitle, ENT_QUOTES, 'UTF-8'); ?>" id="title" name="title" /><br />
        <label for="recip">Recipient<span class="small">(Username)</span></label><input type="text" value="<?php echo htmlentities($orecip, ENT_QUOTES, 'UTF-8'); ?>" id="recip" name="recip" /><br />
        <label for="message">Message</label><textarea cols="40" rows="5" id="message" name="message"><?php echo htmlentities($omessage, ENT_QUOTES, 'UTF-8'); ?></textarea><br />
        <input type="submit" value="Send" />
    </form>
</div>
<?php
}
}
else
{
	echo '<div class="message">You must be logged to access this page.</div>';
}
?>
		<div class="foot"><a href="list_pm.php">Go to my personnal messages</a> - <a href="http://www.webestools.com/">Webestools</a></div>
	</body>
</html>



ประวัติการแก้ไข
2014-06-22 18:01:58
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-22 18:00:59 By : reatilink
 

 

No. 3



โพสกระทู้ ( 9,542 )
บทความ ( 2 )



สถานะออฟไลน์


044.$dn1 = mysql_fetch_array(mysql_query('select count(id) as recip, id as recipid, (select count(*) from pm) as npm from users where username="'.$recip.'"'));
045.if($dn1['recip']==1)
046.{
select count(*) from pm # statement นี้ผิดนะครับ count ใช้กับ * ไม่ได้ครับ ต้องใช้กะชื่อ field
และ 'where username="'.$recip.'"'; ก็ผิดครับ mysql ไม่ใช้ double quotes ครับ ใช้ single quote แก้ซะครับ

บันทัดที่ 44 มันไม่มีการตรวจเช็คเลยนะครับ ทำลักษณะเดียวกันกับอันก่อนครับ เช็คก่อน

แก้เป็น
$qr_chk2='select count(id) as recip, id as recipid, (select count( ชื่อfield ) from pm) as npm from users '.
'where username=\''.$recip.'\' ';
$result_ch=mysql_query( $qr_chk2 );
if(mysql_errno()){
echo $qr_chk2, "<br />'n", mysql_error(); exit;
}

$dn1 = mysql_fetch_array($result_ch);
if($dn1['recip']==1)
{
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-22 18:14:56 By : Chaidhanan
 


 

No. 4



โพสกระทู้ ( 16 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณมากครับ คุณ Chaidhanan


Code (PHP)
044.$dn1 = mysql_fetch_array(mysql_query('select count(id) as recip, id as recipid, (select count(*) from pm) as npm from users where username="'.$recip.'"'));
045.if($dn1['recip']==1)
046.{
select count(*) from pm # statement นี้ผิดนะครับ count ใช้กับ * ไม่ได้ครับ ต้องใช้กะชื่อ field
และ 'where username="'.$recip.'"'; ก็ผิดครับ mysql ไม่ใช้ double quotes ครับ ใช้ single quote แก้ซะครับ

บันทัดที่ 44 มันไม่มีการตรวจเช็คเลยนะครับ ทำลักษณะเดียวกันกับอันก่อนครับ เช็คก่อน

แก้เป็น
$qr_chk2='select count(id) as recip, id as recipid, (select count( ชื่อfield ) from pm) as npm from users '.
'where username=\''.$recip.'\' ';
$result_ch=mysql_query( $qr_chk2 );
if(mysql_errno()){
echo $qr_chk2, "<br />'n", mysql_error(); exit;
}

$dn1 = mysql_fetch_array($result_ch);
if($dn1['recip']==1)
{

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-22 18:49:48 By : reatilink
 


 

No. 5



โพสกระทู้ ( 9,542 )
บทความ ( 2 )



สถานะออฟไลน์



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-22 19:26:04 By : Chaidhanan
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ช่วยที่ครับติดมาหลายวันล่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่