Simple PHP Write-to-file function?

Hi all! I know I should introduce myself here, but I’m in a bit of a rush. I’m not experienced at PHP and am very stuck at how to approach this.

I’ve been putting together a small website for the Felton Food Festival (www.feltonfoodfestival.org.au) with a website builder called BlueVoda, then when I export it, I polish it off a bit by looking at the messy HTML code which is all out of sequence, but meh.

Anyway, on one page there is a section which says “The current highest bid is…” and then, at the moment I have a

[php]<?php include('*filenamehere*'); ?>[/php]

in which echo’s what is in the filenamehere file. The only value in the file is:

$0.00

Because no one has bidded yet. Currently, I have it so that the people holding the event have to manually go through cPanel’s Filemanager to update it, and edit the code and all.

However, I want to be able to have it so that they can just go to a password-protected directory, and there be a form there so they can just type in the amount of the current bid, say they type in $5.00 to the box, and hit submit.
Then the PHP overwrites the existing contents of the file and replaces it with what they put in the one-line text box.

I have found this website, but I have no idea how to change the code so that it draws the info from what is submitted through the web form? The field name would be called “bid” and the form would be submitted with the POST method.

Sorry if I don’t make any sense at all, but I’m still new to this again, and yeah. Thank you heaps! :slight_smile:

Do you have access to MySQL databases? It might be easier to save the bids in a database using the INSERT function containing 3 fields:

id, name, bid

By doing this you can actually keep track of all the different bids as time goes on.

Edit: The Highest bid would be the last entered and when a new bid is entered, it must be higher than the previous.

If the only value you are storing in the filenamehere file is the bid amount, then you could use a very simple form and PHP page to update it:

Form (index.html):
[php]
New Amount:

[/php]

PHP (update_bid.php):
[php]<?php

if(isset($_POST[‘new_bid_amount’])) {
file_put_contents(‘filenamehere’, $_POST[‘new_bid_amount’]); // Update the file name here
} else {
header(‘Location: index.html’);
}[/php]

NB: These files would have to be placed in a password protected directory as anyone who has access to them can change the amount.

I managed to get it to work with the PHP file writing thingo. I just have it so that the administrator logs into the password protected area (this password-protection is through the cPanel Password Protect Directory settings, and is not a script). Anyway, when the admin logs into this, all they do is enter the new highest bid and hit Submit, and then it overwrites the “current-bid.php” file, which is then included onto the page to display the current bid. Hopefully that makes sense :slight_smile:

How would I go about doing this? I have absolutely no experience with MySQL, though this does sound like something I could use to save a lot of time. Because then the bid would also update immediately if it is higher, and therefore no waiting for it to be manually updated.

Thanks all :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service