Jump to content

Recommended Posts

Hello everyone,

I have little problem with my code, it dont work anymore, maybe my host upgraded mysql...

Im getting this error:

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /customers/domain.dk/domain.dk/httpd.www/quotes/index.php on line 151

Select page:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /customers/domain.dk/domain.dk/httpd.www/quotes/index.php on line 175

 

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /customers/domain.dk/domain.dk/httpd.www/quotes/index.php on line 90

Currently quotes in Archive.

 

My index.php code is:

<?

// Connect to the MYSQL table
include "./config.php";
@mysql_connect("$dbhost","$dbuser","$dbpass") or die("Could not connect");
@mysql_select_db("$dbname");

if($action == "save")
{
  $quote = stripslashes($quote);
  $quote = ereg_replace( "\"", """,$quote);
  $quote = ereg_replace( "\n", " ",$quote);
  $quote = strip_tags($quote, '<a><b><i><u>');
  $res = mysql_query("UPDATE $mytable SET quote=\"$quote\" WHERE id=$id");
  header("Location: index.php");
}

##########-----------//-----------##########
if($action == "delete")
{
  $res = mysql_query("DELETE FROM $mytable WHERE id=$id");
  header("Location: index.php");
}

##########-----------//-----------##########





##########-----------//-----------##########
if($action == "savenew")
{
  $quote = stripslashes($quote);
  $quote = ereg_replace( "\"", """,$quote);
  $quote = ereg_replace( "\n", " ",$quote);
  $quote = strip_tags($quote, '<a><b><i><u>');

  mysql_query("INSERT INTO $mytable VALUES(0,\"$quote\",0)") or die ("ERROR LINE 12:".mysql_error());
  $res = mysql_query("SELECT * FROM $mytable ORDER BY id DESC LIMIT 1");
  $ar = mysql_fetch_array($res);
  header("Location: index.php");
}

##########-----------//-----------##########




?>

<HTML>
<TITLE>myQuotes</TITLE>
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
BODY {
SCROLLBAR-FACE-COLOR: #546376; SCROLLBAR-HIGHLIGHT-COLOR: #6e8099; SCROLLBAR-SHADOW-COLOR: #546376; SCROLLBAR-3DLIGHT-COLOR: #293442; SCROLLBAR-ARROW-COLOR: #293442; SCROLLBAR-TRACK-COLOR: #434e5d; SCROLLBAR-DARKSHADOW-COLOR: #29344
}
TEXTAREA {
BORDER-RIGHT: #6e8099 1px solid; BORDER-TOP: #6e8099 1px solid; FONT-WEIGHT: bold; FONT-SIZE: 10px; BORDER-LEFT: #6e8099 1px solid; TEXT-INDENT: 2px; BORDER-BOTTOM: #6e8099 1px solid; FONT-FAMILY: Tahoma, Verdana, sans-serif
}
INPUT {
BORDER-TOP-WIDTH: 1px; FONT-WEIGHT: normal; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 10px; BORDER-LEFT-COLOR: #6e8099; BORDER-BOTTOM-WIDTH: 1px; BORDER-BOTTOM-COLOR: #6e8099; COLOR: #0099ff; BORDER-TOP-COLOR: #6e8099; TEXT-INDENT: 2px; FONT-FAMILY: Tahoma, Verdana, sans-serif; BACKGROUND-COLOR: transparent; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: #6e8099
}
TEXTAREA, .bginput {
BORDER-TOP-WIDTH: 1px; FONT-WEIGHT: normal; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 10px; BORDER-LEFT-COLOR: #6e8099; BORDER-BOTTOM-WIDTH: 1px; BORDER-BOTTOM-COLOR: #6e8099; COLOR: #0099ff; BORDER-TOP-COLOR: #6e8099; TEXT-INDENT: 2px; FONT-FAMILY: Tahoma, Verdana, sans-serif; BACKGROUND-COLOR: transparent; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: #6e8099
}
</style>

<body bgcolor="#293442"><TABLE WIDTH=598 CELLSPACING=0 CELLPADDING=0 BORDER=0 STYLE="font-family:tahoma; font-size:10pt;">


<!--find Quote-->


<TR>
    <TD width="150" VALIGN=TOP> <span class="title"><a href="index.php" style="color:grey;"><font color="#CCCCCC">Index</font></a><font color="#999999"><br>
      <a href="<?echo $PHP_SELF;?>?action=add" style="color:white;"> <font color="#CCCCCC">Add
      Quote</font></a></font></span>
      <form action="<?echo $PHP_SELF;?>" method="POST" name="iskalnik">
      <input type="text" name="squery" value="<?echo $squery;?>" onClick="FillEmpty();" style="width:124">
      <input name="submit" type="submit" value="Find Quote">
      </form>
      <!--/find Quote-->

<!--##########-----------//-----------##########-->

      <?
       $res = mysql_query("SELECT id FROM $mytable");
       $num = mysql_num_rows($res);
       echo "Currently <B>$num</B> quotes in Archive.";
      ?>

<!--##########-----------//-----------##########-->



      <BR>
  </TD>
    <TD width="448" COLSPAN=2 VALIGN=TOP STYLE="padding-left:10px;">
      <?

##########-----------//-----------##########
if($action == "edit")
{
  $res = mysql_query("SELECT * FROM $mytable WHERE id=$id");
  $ar = mysql_fetch_array($res);
  $ar[quotes] = addslashes($ar[quote]);
  $ar[quotes] = ereg_replace( ""","\"", $ar[quote]);
  //$quote = strip_tags($quote, '<a><b><i><u>');
  ?>
      <FORM ACTION="<?echo $PHP_SELF;?>" METHOD=POST>
        <span class="content">Quote:</span><BR>
  <TEXTAREA NAME="quote" STYLE="width:448px; height:180px;"><?echo $ar[quote];?></TEXTAREA>
  <BR>
  <INPUT TYPE="hidden" name="action" VALUE="save">
  <INPUT TYPE="hidden" name="id" VALUE="<?echo $id;?>">
  <INPUT TYPE="submit"  VALUE="Change Quote"><BR>
</FORM>
<?
##########-----------//-----------##########
}


##########-----------//-----------##########

if($action == "add")
{
  ?>
  <FORM ACTION="<?echo $PHP_SELF;?>" METHOD=POST>
        <span class="content">Type new quote:</span><BR>
  <TEXTAREA NAME="quote" STYLE="width:448px; height:180px;"></TEXTAREA>
  <BR>
  <INPUT TYPE="hidden" name="action" VALUE="savenew">
  <INPUT TYPE="submit" VALUE="Save Quote"><BR>
  </FORM>

##########-----------//-----------##########

<?
}

if(empty($action))
{
  if (empty($order)) {$order =  2;}
  if (empty($page))  {$page  =  1;}
  if (empty($hits))  {$hits  = 40;}
  $start = $hits*($page-1);
  $query = "SELECT id FROM $mytable";
  $res = mysql_query("$query");
  $xnum = mysql_num_rows($res);

  $stw2 = (int)($xnum/$hits);
  if ($xnum%$hits > 0) {$stw2++;}
  $np = $page+1;
  $pp = $page-1;
  if ($page == 1) { $pp=1; }
  if ($np > $stw2) { $np = $stw2;}

  echo "Select page:";
  for ($i=1;$i<=$stw2;$i++) {if($page==$i){echo "<B>$i</B>";} else{echo " <A HREF=\"?page=$i\">$i</A> ";}}

  $query  = "SELECT * FROM $mytable ";
  if(!empty($squery)) { $query .= "WHERE quote LIKE \"%$squery%\" ";}
  $query .= " ORDER BY ID desc LIMIT $start,$hits";
  //echo $query;
  $res = mysql_query($query);
  echo "<TABLE CELLSPACING=1 WIDTH=100% CELLPADDING=3 BGCOLOR=#000000 STYLE=\"font-family:tahoma; font-size:10pt;\">";
  echo "<TR BGCOLOR=#6E8099>";
  echo "<TD>Options</TD>";
  echo "<TD>Quote</TD>";
  echo "<TD>Views</TD>";
  echo "</TR>";
  $x=0;
  while($ar = mysql_fetch_array($res))
  {
   $x++;
   if($x==2) {$barva = "CCCCCC";$x=0;} else {$barva = "999999";$x=1;}
   echo "<TR BGCOLOR=#$barva><TD WIDTH=36><A HREF=\"$PHP_SELF?action=edit&id=$ar[id]\"><IMG SRC=\"gfx/icon_edit.gif\" BORDER=0></A> <A HREF=\"$PHP_SELF?action=delete&id=$ar[id]\"><IMG SRC=\"gfx/icon_delete.gif\" BORDER=0></A></TD><TD>$ar[quote]</TD><TD ALIGN=CENTER>$ar[num]</TD></TR>";
  }
  echo "</TABLE>";
}
  ?>
  </TD>
</TR>
</TABLE>

</BODY>
</HTML>

 

 

thank you in advance for any help.

Regards

Neo

 

Link to comment
https://forums.phpfreaks.com/topic/197473-warning-mysql_num_rows/
Share on other sites

The connection is fine, but something is wrong on these lines:

//Line: 151
$xnum = mysql_num_rows($res);

// Line: 175
while($ar = mysql_fetch_array($res))

// Line: 90
$num = mysql_num_rows($res);

 

someone told me that I have to change syntax, but I didnt understand how.

 

If you search for any portion of that error message you will find that it means that your query failed to execute due to an error.

 

For debugging purposes only (remove it after you are done), echo mysql_error(); on the next line right after the line with the mysql_query() statement.

You error is that you are using double quotes around variable definitions in MySQL, when Single Quotes need to be used:

 

  $res = mysql_query("UPDATE $mytable SET quote='$quote' WHERE id=$id") or trigger_error('MySQL Failed: ' . mysql_error());

 

The trigger_error is good for debugging as it would have told you the error from the get go, as PFMaBiSmAd was hinting to.

Hi and thank you,

I added the code and now, I see this message:

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 1Select page:

 

is this something difficult to solve? I dont know much about php or mysql, this is a script I have been using last 4 years and suddenly it dont work anymore.

The most obvious problem with your code is that it relies on register_globals. It is 8 years out of date and should have been updated or replaced long ago. Your web host must have finally (8 years too late) disabled the register_globals setting to prepare for upcoming php6, were register_globals have been completely removed.

 

 

 

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.