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 

script that checks a field and does something

 
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: 2984
Location: Earth

PostPosted: Mon Dec 10, 2007 7:44 am    Post subject: script that checks a field and does something Reply with quote

I've done something here, which i cant find, no matter how much i look and test it

Code:
if(isset($_POST['Submit3'])) {
      $s_num2 = "SELECT * from cards where alttext = '".htmlspecialchars($_POST['3card1'])."' OR alttext = '".htmlspecialchars($_POST['3card2'])."' OR alttext = '".htmlspecialchars($_POST['3card3'])."' OR alttext = '".htmlspecialchars($_POST['3card4'])."' OR alttext = '".htmlspecialchars($_POST['3card5'])."'";
      $r_num2 = mysql_query($s_num2);
      while ($row = mysql_fetch_array($r_num2)) {
         $alttext = $row['alttext'];
         $de = "SELECT * from user_inventory where alttext = '".$alttext."'";
         $deck = mysql_query($de);
         while ($row = mysql_fetch_array($deck)) {
            if($row['status'] == 'collecting') {
               $sql = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";      
               $result4 = mysql_query($sql, $con);
               if (!$result4) { echo( mysql_error()); }      
               while ($row = mysql_fetch_array($result4)) {
                  $update = "UPDATE user_inventory set url = '".$row['url']."' WHERE alttext = '".$alttext."' LIMIT 1";
                  $result = mysql_query($update);
                  if(!$result) { echo(mysql_error()); }
               }
            }
         }
      }
      if(mysql_num_rows($deck) == 0) {
         $sql1 = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";      
         $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()); }
         }
      }
      echo "<br /><br />Cards added sucessfully";
      //mysql_query("INSERT INTO `game` VALUES (NULL, 'doyouhave', '".$_COOKIE['dwtcg']['u']."', '" . $_SESSION['id'] . "')") or die(mysql_error());
   }


What its supposed to do is check to see if the card your getting is part of your collecting set, if it is, the update the existing card, if not, then it enters it as a new row

The problem is it does random things each time
Sometimes it updates, but not inserts, sometimes it doesn't insert, other times it doesn't do anything at all
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
Back to top
 
jthomsonmain
Ardent Poster


Joined: 11 Jan 2008
Posts: 80
Location: Albion, NY (USA)

PostPosted: Fri Jan 11, 2008 5:11 pm    Post subject: Re: script that checks a field and does something Reply with quote

Desbrina wrote:
I've done something here, which i cant find, no matter how much i look and test it

Code:
if(isset($_POST['Submit3'])) {
      $s_num2 = "SELECT * from cards where alttext = '".htmlspecialchars($_POST['3card1'])."' OR alttext = '".htmlspecialchars($_POST['3card2'])."' OR alttext = '".htmlspecialchars($_POST['3card3'])."' OR alttext = '".htmlspecialchars($_POST['3card4'])."' OR alttext = '".htmlspecialchars($_POST['3card5'])."'";
      $r_num2 = mysql_query($s_num2);
      while ($row = mysql_fetch_array($r_num2)) {
         $alttext = $row['alttext'];
         $de = "SELECT * from user_inventory where alttext = '".$alttext."'";
         $deck = mysql_query($de);
         while ($row = mysql_fetch_array($deck)) {
            if($row['status'] == 'collecting') {
               $sql = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";      
               $result4 = mysql_query($sql, $con);
               if (!$result4) { echo( mysql_error()); }      
               while ($row = mysql_fetch_array($result4)) {
                  $update = "UPDATE user_inventory set url = '".$row['url']."' WHERE alttext = '".$alttext."' LIMIT 1";
                  $result = mysql_query($update);
                  if(!$result) { echo(mysql_error()); }
               }
            }
         }
      }
      if(mysql_num_rows($deck) == 0) {
         $sql1 = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";      
         $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()); }
         }
      }
      echo "<br /><br />Cards added sucessfully";
      //mysql_query("INSERT INTO `game` VALUES (NULL, 'doyouhave', '".$_COOKIE['dwtcg']['u']."', '" . $_SESSION['id'] . "')") or die(mysql_error());
   }


What its supposed to do is check to see if the card your getting is part of your collecting set, if it is, the update the existing card, if not, then it enters it as a new row

The problem is it does random things each time
Sometimes it updates, but not inserts, sometimes it doesn't insert, other times it doesn't do anything at all


Well, I dont know SQL, but the basic template for your program should be somthing like:
Code:

input variable
if variable = something
do....

and so on...
It sounds to me like your code may be misinterpreting the card value and doing something that you wanted it to do with a value that you didnt want to put in there. I dont know if SQL has different variable types (int, char, float...), but if you use the wrong type of variable with a command, it may try to convert and give you unexpected results.
_________________
[img:8728bad64c]http://i212.photobucket.com/albums/cc118/jthomsonmain/l2psig.jpg[/img:8728bad64c]
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2984
Location: Earth

PostPosted: Mon Jan 14, 2008 9:15 am    Post subject: Reply with quote

i decided i'd rewrite it, and in doing so i managed to do it in about 1/4 the amount of code
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
Back to top
 
jthomsonmain
Ardent Poster


Joined: 11 Jan 2008
Posts: 80
Location: Albion, NY (USA)

PostPosted: Mon Jan 14, 2008 3:15 pm    Post subject: Reply with quote

Desbrina wrote:
i decided i'd rewrite it, and in doing so i managed to do it in about 1/4 the amount of code

Thats quite an accomplishment! I hope it works for you!
_________________
[img:8728bad64c]http://i212.photobucket.com/albums/cc118/jthomsonmain/l2psig.jpg[/img:8728bad64c]
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2984
Location: Earth

PostPosted: Mon Jan 14, 2008 3:17 pm    Post subject: Reply with quote

it works a lot better actually, my scripting improved since i started this script
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
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