Jump to content

warning: mysql_fetch_assoc() / Warning: mysql_fetch_array()


lalu

Recommended Posts

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:
==================
[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");
?>[/code]
=================

any help will appreciate:)
thanks

Link to comment
Share on other sites

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
[code]
$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);
[/code]
with
[code]
mysql_query ("UPDATE tbagenda SET counter=counter+1 WHERE idAgenda = '$idagenda' ");[/code]
Link to comment
Share on other sites

[quote author=Barand link=topic=107079.msg429067#msg429067 date=1157536777]
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
[code]
$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);
[/code]
with
[code]
mysql_query ("UPDATE tbagenda SET counter=counter+1 WHERE idAgenda = '$idagenda' ");[/code]
[/quote]
Thank you very much Mr Moderator, but now I got an error like this
[code]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mmugmac/public_html/agenda2.php on line 65[/code]
Link to comment
Share on other sites

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

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
Link to comment
Share on other sites

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;
Link to comment
Share on other sites

[quote author=emehrkay link=topic=107079.msg429651#msg429651 date=1157591938]
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;
[/quote]

i have tried your help emehrkey but it doesn't work.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.