Jump to content


Photo

warning: mysql_fetch_assoc() / Warning: mysql_fetch_array()


  • Please log in to reply
8 replies to this topic

#1 lalu

lalu
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 September 2006 - 09:37 AM

I got error like this:
============================
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/web/public_html/agenda2.php on line 15



Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/web/public_html/agenda2.php on line 64
===================

this my code:
==================
<?php
include("inc/header_dalam.php");
if(!isset($asu))
{
	$asu=array();
	session_register("asu");
}

if(!in_array($idagenda,$asu))
{
	//echo count($asu)."--";
	array_push($asu,$idagenda);
	$sql_update="Select counter from tbagenda where idAgenda=".$idagenda;
	$res_update=mysql_query($sql_update);
	$row_update=mysql_fetch_assoc($res_update);
	$counter_x=$row_update[counter]+1;
	
	$sql_update2="Update tbagenda set counter=$counter_x where idAgenda=".$idagenda;
	$res_update2=mysql_query($sql_update2);
}

?>
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="9">&nbsp;</td>
                <td><img src="images/spacer.gif" width="1" height="10"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td>
                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td width="317">
                            	<table border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                  <td width="9">&nbsp;</td>
                                  <td>
                                  <?
	                                  echo '&nbsp;&nbsp;<span class="judul">';
	                                  echo $judul_agenda;
	                                  echo '</span>';
	                            ?>
                                  </td>
                                  <td width="12">&nbsp;</td>
                                </tr>
                              </table>
                            </td>
                            <td width="99" height="31">&nbsp;</td>
                          </tr>
                        </table></td>
                    </tr>
                    <tr> 
                      <td class="contentdalam" valign="top" height="350">
                      <br>
                      <table border=0 cellspacing=0 cellpadding=0 width=100%>
					<tr>
					<td><a href="agenda.php?ver=<?=$ver?>" class="iber">INDEX &nbsp;<?=$judul_agenda?></a></td>
					</tr>
					</table>
					<br>
					<!-- startprint -->
			  		<table border=0 cellspacing=0 cellpadding=2 width=100%>
                       <?
	                  $sqlview = "SELECT * from tbagenda where idAgenda=".$idagenda;
	                  $resagenda1 = mysql_query($sqlview);
	                  while ($rowagenda1 = mysql_fetch_array($resagenda1))
	                  {
	                  	echo '<center><strong>'.$rowagenda1[namaAgenda.$bahasa].'</strong><br>';
	                  	if($rowagenda1[mulaiAgenda]==$rowagenda1[selesaiAgenda])
					{
						if($bahasa=="_e")
						{
							echo date("d M Y", $rowagenda1[mulaiAgenda]).'<br>';
						}
						else
						{
							echo TglIndo($rowagenda1[mulaiAgenda],"s");
						}
					}
					else
					{
						if($bahasa=="_e")
						{
							echo date("d M Y", $rowagenda1[mulaiAgenda])." - ". date("d M Y", $rowagenda1[selesaiAgenda]).'<br>';
						}
						else
						{
							echo TglIndo($rowagenda1[mulaiAgenda],"s")." - ". TglIndo($rowagenda1[selesaiAgenda],"s");
						}
					}
					echo '<br><br></center>';	
	                  	echo $rowagenda1[isiAgenda.$bahasa];
	                                                            
	                  }
	                  echo '</table>';
					?>
					<!-- stopprint -->
					<p align="right">
					<?
					echo '<b>Viewed: '.$viewx.'</b><br>';
					echo '<A HREF="#" onClick="window.open(\'send_agenda.php?idagenda='.$idagenda.'&ver='.$ver.'\',\'Send\',\'width=500,height=350,resizable=yes\')">send to friend</a><br>';
				     ?>
				     <a href="phprint.php">Print Version&nbsp;&nbsp;<img src="images/print.gif" border="0" align="absmiddle"></a> 
					</p>
                      </td>
                    </tr>                    
                  </table></td>
                <td width="20">&nbsp;<td>
              </tr>              
            </table></td>
	  </tr>
      </table>
<?php
include("inc/footer_dalam.php");
?>
=================

any help will appreciate:)
thanks



#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 06 September 2006 - 09:59 AM

change line 14 to

$res_update=mysql_query($sql_update) or die (mysql_error());

That should help to locate the error. Do similar with other query.


BTW: you could accomplish this
	$sql_update="Select counter from tbagenda where idAgenda=".$idagenda;
	$res_update=mysql_query($sql_update);
	$row_update=mysql_fetch_assoc($res_update);
	$counter_x=$row_update[counter]+1;
	
	$sql_update2="Update tbagenda set counter=$counter_x where idAgenda=".$idagenda;
	$res_update2=mysql_query($sql_update2);
with
mysql_query ("UPDATE tbagenda SET counter=counter+1 WHERE idAgenda = '$idagenda' ");

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 arianhojat

arianhojat
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 06 September 2006 - 01:01 PM

maybe need to select correct database that tables are in before running that code like...
$db = 'agendaDB';
mysql_select_db($db) or die ("Unable to select database!");

#4 lalu

lalu
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 September 2006 - 12:32 AM

change line 14 to

$res_update=mysql_query($sql_update) or die (mysql_error());

That should help to locate the error. Do similar with other query.


BTW: you could accomplish this

	$sql_update="Select counter from tbagenda where idAgenda=".$idagenda;
	$res_update=mysql_query($sql_update);
	$row_update=mysql_fetch_assoc($res_update);
	$counter_x=$row_update[counter]+1;
	
	$sql_update2="Update tbagenda set counter=$counter_x where idAgenda=".$idagenda;
	$res_update2=mysql_query($sql_update2);
with
mysql_query ("UPDATE tbagenda SET counter=counter+1 WHERE idAgenda = '$idagenda' ");

Thank you very much Mr Moderator, but now I got an error like this
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mmugmac/public_html/agenda2.php on line 65


#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 September 2006 - 12:38 AM

Add the "..or die (mysql_eror()) to the other query

$resagenda1 = mysql_query($sqlview) or die (mysql_eror()) ;

Do you get any error messages when you have done that?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 lalu

lalu
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 September 2006 - 01:14 AM

<?
	                  $sqlview = "SELECT * from tbagenda where idAgenda=".$idagenda;
                          $resagenda1 = mysql_query($sqlview) or die (mysql_error());
	                  while ($rowagenda1 = mysql_fetch_array($resagenda1))
	                  {

now i got error like this:


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

#7 emehrkay

emehrkay
  • Staff Alumni
  • Advanced Member
  • 1,214 posts

Posted 07 September 2006 - 01:18 AM

it might depend on the version of php you're running if mysql_fetch_assoc would work

try mysql_fetch_array($your_Query, MYSQL_ASSOC);

what kind of field is idAgenda? you may need to close the sting out with a double quote. echo $sql_update and see if it is giving you what you expect

$sql_update="Select counter from tbagenda where idAgenda=".$idagenda;

#8 lalu

lalu
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 07 September 2006 - 04:10 AM

it might depend on the version of php you're running if mysql_fetch_assoc would work

try mysql_fetch_array($your_Query, MYSQL_ASSOC);

what kind of field is idAgenda? you may need to close the sting out with a double quote. echo $sql_update and see if it is giving you what you expect

$sql_update="Select counter from tbagenda where idAgenda=".$idagenda;


i have tried your help emehrkey but it doesn't work.

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 September 2006 - 09:47 AM

Make sure $idagenda actually fas a value in it.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users