FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


small php+mysql script, big reward





henrygl
Hi,

I need a very simple program.

basically like ebay; inputs name+amount and then outputs a table with all bids, as well as the highest one.

like ebay

40 frih$ for who makes it

PM if interested
hexkid
Is this ok?
Code:
<?php
define('BIDFILE', 'bids.txt')
/* ***********************************************************
I need a very simple program.

basically like ebay; inputs name+amount and then outputs
a table with all bids, as well as the highest one.

like ebay
*********************************************************** */
function cmp_function($l, $r) {
  if ($l[1] == $r[1]) {
    if ($l[0] == $r[0]) {
      return 0;
    } else {
      return ($l[0]<$r[0])?-1:1;
    }
  } else {
    return ($l[1] < $r[1])?1:-1;
  }
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  // deal with post data
  if ((isset($_POST['name'])) && ($_POST['name'] != '') && (strpos($_POST['name'], '|') === false)) {
    if ((isset($_POST['amount'])) && ($_POST['amount'] != '') && ((int)$_POST['amount'] > 0)) {
      $bids = file(BIDFILE);
      $bids[] = $_POST['name'] . '|' . (int)$_POST['amount'] . '|' . date('YmdHis');
      file_put_contents(BIDFILE, implode("\n", $bids));
    }
  }

  // redirect
  $URL = 'http://';
  $URL .= $_SERVER['SERVER_NAME'];
  if ($_SERVER['SERVER_PORT'] != '80') {
    $URL .= ':' . $_SERVER['SERVER_PORT'];
  }
  $URL .= $_SERVER['REQUEST_URI'];
  header('Location: ' . $URL);
  exit('Redirected to <a href="' . $URL . '">' . $URL . '</a>');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>bids</title>
</head>
<body>
<form method="post" action="bids.php">
Name: <input type="text" name="name"><br>
Amount: <input type="text" name="amount"><br>
<input type="submit">
</form>
<br><br><br>
<?php
$bids = file(BIDFILE);
$barr = array();
foreach ($bids as $bid) {
  if (trim($bid) != '') {
    $barr[] = explode('|', trim($bid));
  }
}
usort($barr, 'cmp_function');
echo '<table border="1"><tr><th>Name</th><th>Amount</th></tr>';
foreach ($barr as $b) {
  echo '<tr>';
  echo '<td>', $b[0], '</td>';
  echo '<td align="right">', $b[1], '</td>';
  echo '</tr>';
}
echo '</table>';
?>
</body>
</html>
kv
A little off topic. But I am curious to know this. What will people do with all that frih$? Also, is offering frih$ going to motivate people to help others writing code, solving problems, etc?
PatTheGreat42
If you want the next eBay, don't you think Frihost isn't quite the right place to look? Not to knock the coders here, but eBay isn't just a simple PHP script. It's got some secure codin's in there.
Hammy
Hah.. FriHost Ebay. Wooot lol

I think he was just using it as an example lol. I'm sure he has no ambitions in trying to bust ebay :p.

I've seen his little project he's working on anyways Wink
lol

Hammy.
Related topics
PHP, MySQL...
Hot or Not PHP-Nuke script
What's the best PHP Wiki script?
ASP +PHP+MySQL Tutorials
A very good PHP MySQL Tutorial
Php voting script needed (URGENT)
PHP/MYSQL Poll?
Question about a php and mysql script.
Link PHP/Mysql with Outlook Express
Free PHP/MySQL login script
PHP/MySql Sending e-mail subcription confirmation to webmast
Simple PHP Login Script
Need a Registration form PHP/Mysql with email confirmation
php msql quiz script
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.