Jump to content

CoffeeAddict

Members
  • Posts

    35
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

CoffeeAddict's Achievements

Member

Member (2/5)

0

Reputation

  1. Thank you for the response. I did some googling to figure out how to find the errors and these are the ones I'm getting: Notice: Undefined index: accept_buy_request in /home/bestinsh/public_html/dog.php on line 43 Notice: Undefined index: reject_buy_request in /home/bestinsh/public_html/dog.php on line 47 I did additional googling and apparently I'm supposed to use isset in front of POST, which I tried but didn't make any difference. If I understand correctly, no variables are getting passed when the submt button is clicked? I didn't write this code myself, I'm trying to figure out how to fix it without bothering my coder this morning, so far I'm failing, haha
  2. I have a list of requests to purchase a "dog" on my site. The list shows up fine, but when I hit submit or reject, it just redirects to the same page and nothing happens, This was previously working fine and now for whatever reason I can't seem to spot the problem. Help please? This is earlier in the page: if ($_POST['accept_buy_request']) { $user->acceptRequestBuy($_POST['request_id']); } if ($_POST['reject_buy_request']) { $user->rejectRequestBuy($_POST['request_id']); } Further down same page: <table class="table table-striped"> <tr> <td>Requester</td> <td>Amount</td> <td></td> </tr>'; // Get all requests $result = mysql_query("SELECT RB.id, RB.user_id, RB.amount, U.display_name FROM requests_buy RB INNER JOIN users U ON U.id = RB.user_id WHERE RB.dog_id = '$dog->id' ORDER BY RB.created ASC, RB.amount DESC, RB.user_id ASC") or die('Cannot get buy requests: ' . mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo ' <tr> <td><a href="kennel.php?id=', $row['user_id'], '">', $row['display_name'], '</a> (#', $row['user_id'], ')</td> <td>$', number_format($row['amount'], '2'), '</td> <td> <form action="dog.php?id=', $dog->id, '&requests=buy" method="post"> <input type="hidden" name="request_id" value="', $row['id'], '" /> <input type="submit" name="accept_buy_request" value="Accept" /> <input type="submit" name="reject_buy_request" value="Reject" /> </form> </td> </tr>'; } if (!mysql_num_rows($result)) { echo ' <tr> <td colspan="3">No requests to purchase have been made.</td> </tr>'; } echo ' </table> This is in the oop public function acceptRequestBuy($request_id) { if (!$request_id || !is_numeric($request_id) || $request_id < 1) { echo 'Invalid request.'; return; } $request_id = (int)$request_id; $result = mysql_query("SELECT RB.id, RB.user_id, RB.dog_id, RB.amount FROM requests_buy RB INNER JOIN dogs D ON D.id = RB.dog_id WHERE RB.id = '$request_id' AND D.owner = '$this->id' LIMIT 1") or die('Cannot check of legitimate request: ' . mysql_error()); $row = mysql_fetch_assoc($result); if (!$row['id']) { echo 'That request does not exist.'; return; } // Check if the requester can afford the request $requester = new User($row['user_id']); if (!$requester->id) { echo 'That user does not exist.'; return; } if(!$requester->kennelSpaceAvailable){ echo "<div class='alert alert-error'><b>No Kennel Space Available</b><br>The requester doesn't have enough kennel space.</div>"; return; } if ($requester->money - $row['amount'] < 0) { echo 'That user cannot afford to purchase the dog for that amount.'; return; } // Accept the request mysql_query("UPDATE dogs SET owner = '$requester->id}', sell = 0, autosell = 0 WHERE id = '{$row['dog_id']}' LIMIT 1") or die('Cannot update dog: ' . mysql_error()); mysql_query("UPDATE users SET money = money - '{$row['amount']}' WHERE id = '$requester->id}' LIMIT 1") or die('Cannot update buyers money: ' . mysql_error()); mysql_query("INSERT INTO users_transactions (id, date, type, description) VALUES ( '$requester->id}', '" . date("Y-m-d H:i:s") . "', 'Dog', '- $" . number_format($row['amount'], 2, '.', '') . " for a dog.' )") or die('Cannot create buyer transaction: ' . mysql_error()); mysql_query("UPDATE users SET money = money + '{$row['amount']}' WHERE id = '$this->owner' LIMIT 1") or die('Cannot update sellers money: ' . mysql_error()); mysql_query("INSERT INTO users_transactions (id, date, type, description) VALUES ( '$this->owner', '" . date("Y-m-d H:i:s") . "', 'Dog', '+ $" . number_format($row['amount'], 2, '.', '') . " for a dog.' )") or die('Cannot create seller transaction: ' . mysql_error()); // Remove requests to buy mysql_query("DELETE FROM requests_buy WHERE dog_id = '{$row['dog_id']}'") or die('Cannot remove buy requests: ' . mysql_error()); if ($dog->pregnant) { mysql_query("UPDATE litters SET owner = '$requester->id WHERE dam = '{$row['dog_id']}'") or die('Cannot update litter(s): ' . mysql_error()); } $this->money += $row['amount']; unset($_POST); echo 'Successfully accepted a request to purchase this dog.'; return; } public function rejectRequestBuy($request_id) { if (!$request_id || !is_numeric($request_id) || $request_id < 1) { echo 'Invalid request.'; return; } $request_id = (int)$request_id; $result = mysql_query("SELECT RB.id FROM requests_buy RB INNER JOIN dogs D ON D.id = RB.dog_id WHERE RB.id = '$request_id' AND D.owner = '$this->id' LIMIT 1") or die('Cannot check of legitimate request: ' . mysql_error()); $row = mysql_fetch_assoc($result); if (!$row['id']) { echo 'That request does not exist.'; return; } // Remove request to buy mysql_query("DELETE FROM requests_buy WHERE id = '{$row['id']}'") or die('Cannot remove buy request: ' . mysql_error()); unset($_POST); echo 'Successfully rejected a request to purchase this dog.'; return; }
  3. Got it, tried it with the quotes and no space, but forgot to capitalize the words! Works great now. Thank you!
  4. They are both listed as Blue Merle. With the space. If I change them to blue_merle with the underscore, it works. But I'd like to avoid having to change it.
  5. Thanks! I just tried that and it still lets me breed two merles together when it should be throwing the echo message
  6. Below is the code I'm trying to use, it works perfectly IF the color in the database is listed as "blue_merle". Problem being, it is not, it's listed as "Blue Merle". How can I make this continue to work without having to change the way the color is listed in the database? If I put "Blue Merle" in the php code then it just causes an error because of the space between the words. Help please? I feel like this is probably really simple to fix but it's going right over my head. else if ($dog1->color == blue_merle && $dog2->color == blue_merle) { echo '<p>You cannot breed two merles.</p>';
  7. I have a project I'm working on and I'm stuck on how to order results closest to a specific number. I have a breed of dog with an ideal number. We will say 250 For that breed I have 5 different dogs all that have their own set of numbers. I then added those together and now have a single total for each of those 5 dogs. Out of those 5 numbers, I need to order them by the closest to 250. Now some may be below 250 or above 250. Lets say my totals for these 5 dogs were 240 310 122 109 87 That right there is how I would want them ordered. Because 240 is closest to 250 and so on. I know how to order by ascending or desceding, but not how to order according to a specific number. Help please?
  8. Thanks for your reply! The user's last log in time is recorded but not their last active time on each page load. I'll probably end up using the last log in instead. Check the user's last log in time Check the news latest update time if the user's log in time is after the news time, display the bar That's as far as I've gotten when it comes to psuedo code, and even then I have a hard time translating it. I'm pretty new to php
  9. I'm trying to add the following CSS notification bar to my site to notify the user when the news is updated. http://deepubalan.com/blog/2012/02/14/notify-pure-css-notification-bar-using-target-pseudo-class/ I cannot wrap my brain around how to make it show up only when an update has been made to the database since the user's last visit. Obviously if the user has already seen the news I don't want to keep showing the bar. When I make a news post the time is recorded in the database, so I'm assuming I need to check the user's last visit time, compare that to the time the last news was posted and then display or not display the bar? And somehow I need to check if the user has clicked the bar or not... That seems like the logical way, but I don't know where to start writing the actual code. Help please?
  10. I will give that a shot, thank you! Looking it over it seems like it would only return a total of two results, instead of two results for each model. But I could be wrong.
  11. That would work except it doesn't account for ordering each make by it's mileage. The results should look something like this: Honda Civic - mileage 21000 Civic - mileage 12000 Ford Fusion - mileage 145000 Fusion - mileage 4000 and so on...
  12. There is no form to define the make or model beforehand, I just want to fetch the data and then display it.
  13. That would work, but then it would return the highest and second highest mileage for all the cars and not just for each make and model, right? I can select the make and model of the car, and order that by mileage and desc limit 2, however I then need to do that for EVERY make and model, and if if got 50 different types of cars that's a lot of code. Just looking for a shorter way to cycle through all the different cars and return each individual results without writing 50 queries.
  14. To use an example, let's say I have a list of 50 cars, with their make and model and mileage in a database. I want to return results that list all the fords fusions with the first and second highest mileage, all the honda elements with the first and second highest mileage, etc. etc. and make both of those results (the first and second) a variable so I can put them neatly into a table on the website. Is there any way of doing that without writing 50 different queries for each make and model? If I have a lot of different cars that could get time consuming and be a lot of code, correct?
×
×
  • 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.