Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2011
    Location
    Space
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question For loop not updating database

    Hi, I need a fresh set of eyes to help me out with this. It's one of them small but probably obvious problems I just can't see.
    Anyway, all of this works up until the point of updating the requested item and I can't for the life of me see why the hell not...

    PHP Code:
    <?php
    if($_POST['item']){
        
    $array1 = array("item 1""item 2""item 3""item 4""item 5""item 6""item 7""item 8""item 9");
        
    $array2 = array("item_1""item_2""item_3""item_4""item_5""item_6""item_7""item_8""item_9");
        for(
    $i=0;$i<=8;$i++){
            if(
    $array1[$i] == $_POST['item']){
                if(
    $_SESSION['items'][$i] > 0){ // If the user has enough of the used item
                    
    $_SESSION['items'][$i] -= 1// update the item session
                    
    $rq $array2[$i];
                    
    mysql_query("UDPATE items SET $rq = $rq - 1 WHERE uid = '{$_SESSION['myid']}'"); // Update used item
                
    }
            }
        }
    }

  2. #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,840
    Thanks
    3
    Thanked 448 Times in 438 Posts
    What debugging have you done to find where the problem is at?

    Is $_POST['item'] even set? Does $_POST['item'] contain one of the expected values? Does it contain some extra white-space that would prevent the code from matching the value in it? Are there any $_SESSION variables at all? Does the $_SESSION['items'] entry, that has the same numerical index 0-8 that matches the submitted $_POST['item'], have a positive quantity? Does $_SESSION['myid'] exist and have an expected value? Is the mysql query what you expect? Is the query producing an error when it runs?

    In short, you are the only one who can determine what your code and data is actually doing, what have you found?
    Last edited by CFMaBiSmAd; 07-23-2014 at 06:59 AM.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •