W pierwszym postąpieniu, skrypt akceptuje nizsza cene niz w ofercie, nastepnie juz tylko wieksze. Dlaczego?



  1.  
  2.  
  3. <?php
  4.  
  5.  
  6. include("config.php");
  7. include("functions.php");
  8.  
  9. $db = mysql_connect($dbhost, $dbuser, $dbpassword);
  10. mysql_select_db($dbdatabase, $db);
  11.  
  12. $validid = pf_validate_number($_GET['id'], "redirect", $config_basedir);
  13.  
  14. if($_POST['submit']) {
  15.  
  16. if(is_numeric($_POST['bid']) == FALSE) {
  17. header("Location: " . $config_basedir . "itemdetails.php?id=" . $validid . "&error=letter");
  18. }
  19.  
  20. $theitemsql = "SELECT * FROM items WHERE id = " . $validid . ";";
  21. $theitemresult = mysql_query($theitemsql);
  22. $theitemrow = mysql_fetch_assoc($theitemresult);
  23.  
  24. $checkbidsql = "SELECT item_id, max(amount) AS highestbid, count(id) AS number_of_bids FROM bids WHERE item_id=" . $validid . " GROUP BY item_id;";
  25. $checkbidresult = mysql_query($checkbidsql);
  26. $checkbidnumrows = mysql_num_rows($checkbidresult);
  27.  
  28. if($checkbidnumrows == 0) {
  29. if($theitemrow['startingprice'] > $_POST['bid']) {
  30. header("Location: " . $config_basedir . "itemdetails.php?id=" . $validid . "&error=lowprice#bidbox");
  31. }
  32. }
  33. else {
  34. $checkbidrow = mysql_fetch_assoc($checkbidresult);
  35.  
  36. if($checkbidrow['highestbid'] > $_POST['bid']) {
  37. header("Location: " . $config_basedir . "itemdetails.php?id=" . $validid . "&error=lowprice#bidbox");
  38. }
  39. }
  40.  
  41. $inssql = "INSERT INTO bids(item_id, amount, user_id) VALUES("
  42. . $validid
  43. . ", " . $_POST['bid']
  44. . ", " . $_SESSION['USERID']
  45. . ");";
  46. mysql_query($inssql);
  47.  
  48. header("Location: " . $config_basedir . "itemdetails.php?id=" . $validid);
  49. }
  50. else {
  51.  
  52. require("header.php");
  53.  
  54. $itemsql = "SELECT UNIX_TIMESTAMP(dateends) AS dateepoch, items.* FROM items WHERE id = " . $validid . ";";
  55. $itemresult = mysql_query($itemsql);
  56.  
  57. $itemrow = mysql_fetch_assoc($itemresult);
  58.  
  59. $nowepoch = mktime();
  60. $rowepoch = $itemrow['dateepoch'];
  61.  
  62. if($rowepoch > $nowepoch) {
  63. $VALIDAUCTION = 1;
  64. }
  65.  
  66. echo "<h1>" . $itemrow['name'] . "</h1>";
  67.  
  68. $imagesql = "SELECT * FROM images WHERE item_id = " . $validid . ";";
  69. $imageresult = mysql_query($imagesql);
  70. $imagenumrows = mysql_num_rows($imageresult);
  71.  
  72. $bidsql = "SELECT item_id, MAX(amount) AS highestbid, COUNT(id) AS number_of_bids FROM bids WHERE item_id=" . $validid . " GROUP BY item_id;";
  73. $bidresult = mysql_query($bidsql);
  74. $bidnumrows = mysql_num_rows($bidresult);
  75.  
  76. echo "<p>";
  77.  
  78. if($bidnumrows == 0) {
  79. echo "<strong>This item has had no bids</strong> - <strong>Starting Price</strong>: " . $config_currency . sprintf('%.2f', $itemrow['startingprice']);
  80. }
  81. else {
  82. $bidrow = mysql_fetch_assoc($bidresult);
  83. echo "<strong>Number Of Bids</strong>: " . $bidrow['number_of_bids'] . " - <strong>Current Price</strong>: " . $config_currency . sprintf('%.2f', $bidrow['highestbid']);
  84. }
  85.  
  86. echo " - <strong>Auction ends</strong>: " . date("D jS F Y g iA", $rowepoch);
  87.  
  88. echo "</p>";
  89.  
  90. if($imagenumrows == 0) {
  91. echo "No images.";
  92. }
  93. else {
  94. while($imagerow = mysql_fetch_assoc($imageresult)) {
  95. echo "<img src='./images/" . $imagerow['name'] ."' width='200'>";
  96. }
  97. }
  98.  
  99. echo "<p>" . nl2br($itemrow['description']) . "</p>";
  100.  
  101. echo "<a name='bidbox'></a>";
  102. echo "<h2>Bid for this item</h2>";
  103.  
  104. if(isset($_SESSION['USERNAME']) == FALSE) {
  105. echo "To bid, you need to log in. Login <a href='login.php?id=" . $validid . "&ref=addbid'>here</a>.";
  106. }
  107. else {
  108. if($VALIDAUCTION == 1) {
  109. echo "Enter the bid amount into the box below.";
  110. echo "<p>";
  111.  
  112. switch($_GET['error']) {
  113. case "lowprice":
  114. echo "The bid entered is too low. Please enter another price.";
  115. break;
  116.  
  117. case "letter":
  118. echo "The value entered is not a number.";
  119. break;
  120. }
  121.  
  122. ?>
  123.  
  124. <form action="<?php echo pf_script_with_get($SCRIPT_NAME); ?>" method="post">
  125. <table>
  126. <tr>
  127. <td><input type="text" name="bid"></td>
  128. <td><input type="submit" name="submit" value="Bid!"></td>
  129. </tr>
  130. </table>
  131. </form>
  132.  
  133. <?php
  134. }
  135. else {
  136. echo "This auction has now ended.";
  137. }
  138.  
  139. $historysql = "SELECT bids.amount, users.username FROM bids, users WHERE bids.user_id = users.id AND item_id = " . $validid . " ORDER BY amount DESC";
  140. $historyresult = mysql_query($historysql);
  141. $historynumrows = mysql_num_rows($historyresult);
  142.  
  143. if($historynumrows >= 1) {
  144. echo "<h2>Bid History</h2>";
  145. echo "<ul>";
  146.  
  147. while($historyrow = mysql_fetch_assoc($historyresult)) {
  148. echo "<li>" . $historyrow['username'] . " - " . $config_currency . sprintf('%.2f', $historyrow['amount']) . "</li>";
  149. }
  150.  
  151. echo "</ul>";
  152. }
  153. }
  154. }
  155.  
  156. require("footer.php");
  157.  
  158. ?>
  159.  
  160.  
  161.  
  162.