Jump to content

Got me Puzzled


supanoob

Recommended Posts

It could be that i am tired, but i cant seem to figure out why the following script will not work in my cron job, Basically what it is meant to do is this:

 

step 1: update the auction time

step 2: check if the time is 0

step 3: check see if the auction was sold if not insert the news item saying it wasnt sold

step 4: Check to see if the house was bought, if so insert news items to the buyer and seller, update accounts etc

 

anyway here is the code, might be a little sloppy sorry if it is.

 

<?php
$dbh=mysql_connect ("localhost", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("wwwcrim_legends");

$sql2="UPDATE house_auctions SET auction_length=auction_length-1 where auction_length > 0";
if(mysql_query($sql2))
{
echo $sql2;
}

$query="select highest_bid, who_bid, location, auction_id, who_selling, owned_id, auction_length, total_bids from house_auctions where auction_id='$bid_on'";
      $result=mysql_query($query);
      if (!$result)
      {
      die(mysql_error());
      }
      $num_rows=mysql_num_rows($result);
      
      $row=mysql_fetch_array($result);
      $highest_bid=($row['highest_bid']);
      $who_bid=($row['who_bid']);
      $location=($row['location']);
      $auction_id=($row['auction_id']);
      $who_selling=($row['who_selling']);
      $owned_id=($row['owned_id']);
      $auction_length=($row['auction_length']);
      $total_bids=($row['total_bids']);
      
      $query="select auction_id, who_selling, starting_bid, highest_bid, who_bid, owned_id, location, auction_length, total_bids from house_auctions where auction_length = 0";
      $result=mysql_query($query);
      if (!$result)
      {
      die(mysql_error());
      }
      $num_rows=mysql_num_rows($result);

    while ($row=mysql_fetch_array($result))
      {
      $auction_id=($row['auction_id']);
      $starting_bid=($row['starting_bid']);
      $who_selling=($row['who_selling']);
      $highest_bid=($row['highest_bid']);
      $who_bid=($row['who_bid']);
      $owned_id=($row['owned_id']);
      $location=($row['location']);
      $auction_length=($row['auction_length']);
      $total_bids=($row['total_bids']);
      
      if ($total_bids = '0')
      {
        if ($account_win == '1')
        {
        $query="insert news (whos_news, news_type, house_bid) values ('$who_selling', 'auction_unsold', '$auction_id')";
        $result=mysql_query($query);
        
        $sql2="UPDATE accounts SET account_news=account_news+1 where account_id='$who_selling'";
        if(mysql_query($sql2));
        }
      }
      
      if ($total_bids > '0')
      {
      $sql2="UPDATE houses_owned SET owned_by_id='$who_bid' where house_owned_id=$owned_id";
      if(mysql_query($sql2))
      
      $sql2="UPDATE accounts SET account_money=account_money+$highest_bid where account_id=$who_selling";
      if(mysql_query($sql2))
      
        if ($account_win == '1')
        {
        $query="insert news (whos_news, news_type, house_bid) values ('$who_bid', 'auction_won', '$auction_id')";
        $result=mysql_query($query);
        
        $sql2="UPDATE accounts SET account_news=account_news+1 where account_id='$who_bid'";
        if(mysql_query($sql2));
        
        $query="insert news (whos_news, news_type, house_bid, money_increase) values ('$who_selling', 'auction_sold', '$auction_id', '$highest_bid')";
        $result=mysql_query($query);
        
        $sql2="UPDATE accounts SET account_news=account_news+1 where account_id='$who_selling'";
        if(mysql_query($sql2));
        }
   
      }   
      }


?>

Link to comment
https://forums.phpfreaks.com/topic/117642-got-me-puzzled/
Share on other sites

It could be that i am tired, but i cant seem to figure out why the following script will not work in my cron job, Basically what it is meant to do is this:

 

And what does it do?

 

It is basically meant to check to see if the house has been sold at auction or not, if so update the buyer and sellers news items with the correct info and swap the house over, if not then it updates the seller news with correct info

Link to comment
https://forums.phpfreaks.com/topic/117642-got-me-puzzled/#findComment-605089
Share on other sites

That doesn't answer my question.

 

You have an undefined variable $bid_on within your first SELECT query, maybe that has something to do with your problem? Which by the way, you have still haven't told us about.

 

ohhh right sorry, i thought you meant what was the script meant to do. It doesnt do anything, got rid of the first query since it doesnt do anything anyway.

 

But it does nothing, nothing updates, or changes anywhere.

Link to comment
https://forums.phpfreaks.com/topic/117642-got-me-puzzled/#findComment-605097
Share on other sites

Well, it needs some debuging. Queries should always be wrapped in if() statements to check they worked. If other queries rely on these queries working they also need to be within the same if. eg;

 

if (mysql_query($sql)) {
  if (mysql_query($moresql)) {
    echo "success"
  } else {
    echo mysql_error();
  }
} else {
  echo mysql_error();
}

 

Also, make sure you have error reporting and display error on. You are testing the script itself before having cron execute it aren't you?

Link to comment
https://forums.phpfreaks.com/topic/117642-got-me-puzzled/#findComment-605105
Share on other sites

I do check to see if it works first, however i wasnt echoing the queries etc after doing that i found out it stops after the select query on the while, i checked to make sure it was picking up the bids and it was this is the results from all the echoing:

 

Update auctions SQL:

UPDATE house_auctions SET auction_length=auction_length-1 where auction_length > 0

 

select auction_id, who_selling, starting_bid, highest_bid, who_bid, owned_id, location, auction_length, total_bids from house_auctions where auction_length = 0

Rows: 3

 

select query 1:

select auction_id, who_selling, starting_bid, highest_bid, who_bid, owned_id, location, auction_length, total_bids from house_auctions where auction_length = 0

Total Bids: 5

 

select query 1:

select auction_id, who_selling, starting_bid, highest_bid, who_bid, owned_id, location, auction_length, total_bids from house_auctions where auction_length = 0

Total Bids: 0

 

select query 1:

select auction_id, who_selling, starting_bid, highest_bid, who_bid, owned_id, location, auction_length, total_bids from house_auctions where auction_length = 0

Total Bids: 0

Link to comment
https://forums.phpfreaks.com/topic/117642-got-me-puzzled/#findComment-605468
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.