Jump to content

What could be the possibly problems?


TeddyKiller

Recommended Posts

Lets say $id = 7 (for my user)

 

$id = '7';
$gold1 = '8';
$gold2 = '9';
$query = $db->execute("update `users` set `gold`=? where `id`=?", array($id, $gold1 + $gold2)) or die(mysql_error());
if($query){ echo "Completed"; } else { echo "Not Completed"; }

 

Whats wrong with that query for example?

For some reason.. when I use something similar to that (Code displayed at the bottom) It always echo's "Completed" even though the ID is correct, it doesn't update the users table where my ID is. I don't seem to understand why. I've run into problems like this before and there has been no solution. I'm stumped.

 

What could possibly be the problem? I recieve no errors or anything.

 

switch($_GET['act'])
{
    case "buy":
        
        break;
        
    case "sell":
        if (!$_GET['item']) //No item
        {
            header("Location: mall.php?get=".$_GET['get']."");
            break;
        }
        
        //Select the item from the database
        $item = $_GET['item'];
        $amount = $_GET['amount'];
        $get = $_GET['get'];
        
        $price = $_GET['amount'] * $_GET['price']; //Gets the price from the URL
        
        
        $query = $db->execute("select * from `users` where `".$item."` >= '".$amount."' and id=?", array($player->id)) or die(mysql_error());
        //User does not have the amount of items
        if($query->recordcount() == 0){ echo "Sorry you do not have ".$amount." ".ucwords($item).""; break;}
        
        //Check to make sure clicking Sell wasn't an accident
        if (!$_POST['sure'])
        {
            echo "Are you sure you want to sell <strong>".$amount."".ucwords($item)."</strong> for <strong>".$price."</strong> gold?<br /><br />\n";
            echo "<form method=\"post\" action=\"mall.php?get=".$get."&act=sell&item=".$item."&amount=".$amount."&price=".$price."\">\n";
            echo "<input type=\"submit\" name=\"sure\" value=\"Yes, I am sure!\" />\n";
            echo "</form>\n";
            break;
        }
        
        // This query executes, and completes (As the echo doesn't come up, and no errors) but doesn't update the table?!
        $query = $db->execute("update `users` set `gold`=? and `".$item."`=? where `id`=?", array($player->gold + $price, $player->$item - $amount, $player->id)) or die(mysql_error());
        
        if($query){
        $player = check_user($secret_key, $db); //Get updated user info
        
        echo "You have sold <strong>".$amount."</strong> <strong>".ucwords($item)."</strong> for <strong>".$price."</strong> gold.<br /><br />\n";
        echo "<a href=\"mall.php?get=".$get."\">Return to shop</a>";
        break;
        } else { echo "God damn query didn't work"; }
    }

 

This query is the one with the problem

$query = $db->execute("update `users` set `gold`=? and `".$item."`=?where `id`=?", array($player->gold + $price, $player->$item -$amount, $player->id)) or die(mysql_error());

 

All the echo's work out perfect. $player->id is also used in the script and comes out with the right result. It just doesn't update the table or anything?

 

The other problem I was having which is the same as this, also involved updating the users table, the echo's come out fine.. it just doesn't update.

 

It updates everywhere else when it uses the update query, just not for these.

 

This is probably unhealthy but the database table `users` has 148 collums.. (Not rows)

Link to comment
Share on other sites

Hiya!

 

$id = '7';
$gold1 = '8';
$gold2 = '9';

 

You don't need the * ' ' * you can just have the number, anyways maybe try this.

 

$id = 7;
$goldo = 8;
$goldt = 9;
$addition = $goldo + $goldt;
$query = $db->execute("update `users` set `gold`=? where `id`=?", array($id, $addition)) or die(mysql_error());
if($query){ echo "Completed"; } else { echo "Not Completed"; }

 

James.

Link to comment
Share on other sites

Well.. take a look at the biggest chip of code, thats the code with the problem. The code above was just.. more or less a quick example.

I tried what you did and did the addition as..

$addition = $player->gold + $price

and had $addition in the array instead. Although it still never done it.

 

I realised that "} else { echo "God damn query didn't work"; }" was placed after "break;" I put it before and still never got that echo. So the query is being completed. but I dont know why it dont update =[

 

 

I just found out that when the query runs (I think) it's actually removing ALL the users gold. I had "12341214121" for testing or something, and it just disappeared when I used case: sell.

Link to comment
Share on other sites

That's the example! to say that it says it runs the query and completes it!

$query = $db->execute("update `users` set `gold`=? and `".$item."`=?where `id`=?", array($player->gold + $price, $player->$item -$amount, $player->id)) or die(mysql_error());

 

This is the actual query with the problem! >.<

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.