Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

error with script

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 3010
Location: Earth

PostPosted: Mon Dec 17, 2007 4:19 am    Post subject: error with script Reply with quote

Code:
function normal() {
   $con = mysql_connect('localhost', '****', '****') or die('Could not connect to database!');
    mysql_select_db('****', $con);
   $sql = "(SELECT * FROM cards WHERE worth = 1 AND `deny`=0 ORDER BY RAND() LIMIT 1)";       
   $result2 = mysql_query($sql, $con);
   if (!$result2) { echo( mysql_error()); }
   while ($row = mysql_fetch_array($result2)) {
      echo "<img src=\"{$row[url]}\" alt=\"{$row[alttext]}\" /> " ;
      $alt = $row['alttext'];
      $collecting = "SELECT * FROM user_inventory WHERE alttext = '".$alt."' and name = '".$_COOKIE['dwtcg']['u']."' and status = 'collecting' LIMIT 1";
      $collect = mysql_query($collecting);
      while ($row = mysql_fetch_array($collect)) {
         if($row['status'] == 'collecting') {
            $sql = "SELECT * FROM `cards` WHERE alttext = '".$alt."'";      
            $result = mysql_query($sql, $con);
            if (!$result) { echo( mysql_error()); }      
            while ($row = mysql_fetch_array($result)) {
               $update = "UPDATE user_inventory set url = '".$row['url']."' WHERE alttext = '".$alt."' LIMIT 1";
               $result = mysql_query($update);
               if(!$result) { echo(mysql_error()); }
            }
         } elseif(mysql_num_rows($collect) == 0) {
            $sql1 = "SELECT * FROM `cards` WHERE alttext = '".$alt."'";      
            $result1 = mysql_query($sql1, $con);
            if (!$result1) { echo( mysql_error()); }      
            while ($row = mysql_fetch_array($result1)) {
               $add = "INSERT INTO `desbrina_sw`.`user_inventory` (`ID` ,`name` ,`url` ,`alttext` ,`deck` ,`user_id` ,`card_id` ,`status` ,`worth` ,`amount` ,`type`) VALUES (NULL , '".$_COOKIE['dwtcg']['u']."', '".$row['url']."', '".$row['alttext']."', '".$row['deck']."', '".$_COOKIE['dwtcg']['i']."', '".$row['ID']."', 'undefined', '".$row['worth']."', '".$row['amount']."', '".$row['type']."')";
               $result = mysql_query($add);
               if(!$result) { echo(mysql_error()); }
            }
         }
      }
   }
}


I seem to have a problem with the piece of code
It works correctly, ading and updating, but it gives this error when getting to one that needs to be updated not added
Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/home/desbrina/public_html/games/insert.php on line 19


Whats causing it
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
My Stories
Back to top
 
nooc
Master Poster


Joined: 10 Aug 2005
Posts: 215


PostPosted: Tue Dec 18, 2007 1:26 am    Post subject: Reply with quote

If your query returns a false result, don't continue operating on it, instead, try outputtin some debugging info. That way you'll actually find your bugs.. Wink
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 3010
Location: Earth

PostPosted: Tue Dec 18, 2007 2:47 am    Post subject: Reply with quote

i found the problem. it was to do with the fact i was using $sql and $result multiple times. Soon as i changed them to something else it started working
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
My Stories
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com