How to update a webpage from another webpage?
October 27, 2005 8:49 AM   Subscribe

Help me create a webpage that has data in a table that I can update via another webpage.

I have created a (rough draft) page that will be used to display the results of a volleyball tournament. The page is currently set to automatically refresh between two pages every ten seconds. (the data in the table has been manually coded)
I want to be able to update the results on these pages through another similar page using fields or drop down menus (rather than manually changing the html and re-ftp'ing the pages each time.)
I am fairly comfortable with learning new concepts, I think my biggest problem right now is not knowing the exact search terms to use in order to find the information that I need. I'd like to keep this as simple as possible, so I'm not really worried about elegance of execution or efficiency at this time. Quick and dirty is the order of the day.
posted by davey_darling to Computers & Internet (10 answers total)
 
That's an apache server with PHP installed. You've got a couple of quickie options.

Simplest would be to create a file for each score result, a la Selkirk-Dryden.score and put the number in it, say 23-43.

Then change your page from .html to .php and in every place where there should be a score, put in

< ?php @readfile(selkirk-dryden.score); ?>

where that filename is the appropriate one. (the filename needs to be in quotes but this text box is not escaping them)

You can then just edit the individual files to put the scores in as they happen. The @ supresses the no-file error so you don't HAVE to create the individual files ahead of time. If you create the file ahead of time you can put the nbsp into them, otherwise you should put it in front of the php call.
posted by phearlez at 9:09 AM on October 27, 2005


I'm liking that answer, now I just need to know how to set up another page that will actually create those files based on my input..
posted by davey_darling at 9:16 AM on October 27, 2005


I use table maker, a simple perl script that uses server-side includes, to do exactly this for one of my clients. I haven't had to ever touch it. He wants $10 for it now, but if you're starting from scratch, it would save you a lot of time.
posted by ulotrichous at 9:16 AM on October 27, 2005


oop, never mind. looks like it's vanished. sorry.
posted by ulotrichous at 9:17 AM on October 27, 2005


Can you not just create the files manually? If you create a page that makes those files you then get into issues of security, overwriting existing files, file permissions, etc

If you really want to do it, the function you're interested in is file_put_contents(filename, filecontents) and you'll need to have write permission into the directory where you put them. Make sure to put them in a subdirectory and give write permission to THAT so nobody finds a way to clobber your actual webpages.
posted by phearlez at 9:25 AM on October 27, 2005


davey_darliing, I had to hack together something for a similar 'problem' for tennis draw results and some news stuff. Used PHP & CSV files.

This is graceless and unpoetic code, I'm not really a programmer, and only worked on it until it functioned.

But let's see now...

1. This is the admin page, it uses hardcoded PHP to generate a big form and populate it with any data you've entered previously, read from the CSV file.

< ?phpbr> // Which file is it reading from and writing to?
$filename = "blue.csv";

$fp = fopen($filename,"r");

// Check for problems with the database file.
if (!is_readable($filename)) {
print "Error: couldn't find the database!";
exit;
}

if (!is_writeable($filename)) {
print "Error: the database isn't writeable!";
exit;
}

$array = file($filename);

foreach($array as $row) {
$line = explode("|", $row);
}

// The form, as many as you want to put in the array (eg. $line[55] or $line[99]).
print "




";

fclose($fp);

?>


2. That submits to another PHP file containing this:

< ?phpbr> // Define our file name.
$filename = "blue.csv";

// Check for problems with the database file.
if (!is_readable($filename)) {
print "Error: couldn't find the database!";
exit;
}

if (!is_writeable($filename)) {
print "Error: the database isn't writeable!";
exit;
}

// Open the file for writing.
$fp = fopen($filename,"w");

if (!$fp) {
print "Error: can't write to the database!";
exit;
}

// What is being written?
$stringtowrite=$a1."|".$a2."\n";

// If the form has been submitted, do things, otherwise display the form.
if ($Submit) {
fwrite($fp, $stringtowrite);
print "Success. Your update is in the database.Click here to go back to the form.";
//readfile($filename);
} else {
print "Nothing to do.";
}

fclose($fp);?>


3. And this is the bit for public consumption, this just reads the guff out of the CSV file, you'll need a bunch of HTML in here.

< ?phpbr>
// Define our file name.
$filename = "blue.csv";
$fp = fopen($filename,"a+");

// Check for problems with the database file.
if (!is_readable($filename)) {
print "Error: couldn't find the database!";
exit;
}

if (!is_writeable($filename)) {
print "Error: the database isn't writeable!";
exit;
}

$array = file($filename);

foreach($array as $row) {
$line = explode("|", $row);
print "Team 1: ".$line[0]."
Team 2: ".$line[1]." etc.";
}

?>



Now, I used this for tennis draws with stupid-many results, in waaay too many columns and rows and it worked okay. I suggest that your admin page for each draw (looks like gold and blue) look really much the same as the public page, but of course the admin page has a huge form with input fields where on the public page it just prints some text into a table cell.

Don't know how well the code will show up - looks like you'll need to add a '< ? php' bit at the beginning of each code chunk, and those form fields might be rendered rather than just displaying the code, so perhaps you should look at the source of this page.br>
Oh, and make sure the admin pages are in a password protected sub-folder (I just used htaccess), and your .csv files (I've replaced the original with 'blue.csv' in my code examples, but you'll also want one called gold.csv or something) will need to be writeable by the server too, I guess.

Good luck.
posted by The Monkey at 4:06 PM on October 27, 2005


You say you don't want to "update the HTML and FTP every time". If it was me, I'd just use an FTP/text editor combination which makes that second step transparent.

Rather than update, then FTP, you could use something which allows you to update, hit Save, and the Save performs the FTP.

It would be as simple as using a form really. If you find yourself getting lost in the HTML, just add some prominent comment tags.

The thing is, I can't remember the Windows app I used to do this with. I use BBEdit and Interarchy on OS X at the moment, but does CuteFTP or CoffeeCup FTP have this feature?

I know this isn't the answer to your question, but I think it's just as good in its way. There's no reason why you can't build a form-based, scripted version, but essentially, it's a very simple task and you might be over-complicating it.
posted by AmbroseChapel at 7:21 PM on October 27, 2005


Ambrosechapel, SmartFTP has that feature -- when you open a remote file in "edit" mode, it will automatically re-put the file on save. And it's free.

and if you want to make the remote edit process as simple as possible, make a php page with a lsit of variables at the top

$game1winner = ';
$game2winner = ';
$game3winner = ';
// etc.


and then include these in the tag-soup portion of the page ONCE when you set up the page initially.
<?php echo $game1winner; ?>
etc.

So when you jump into the page to add a result, you don't have to scroll or think.
posted by misterbrandt at 7:57 PM on October 27, 2005


AmbroseChapel writes "The thing is, I can't remember the Windows app I used to do this with. I use BBEdit and Interarchy on OS X at the moment, but does CuteFTP or CoffeeCup FTP have this feature"

WinSCP has a feature to keep your local and server copies synced.
posted by Mitheral at 11:07 AM on November 14, 2005


[MetaTalk thread was closed. Reposting The Monkey's code for you, unmangled.]

davey_darliing, I had to hack together something for a similar 'problem' for tennis draw results and some news stuff. Used PHP & CSV files.

This is graceless and unpoetic code, I'm not really a programmer, and only worked on it until it functioned.


But let's see now...

1. This is the admin page, it uses hardcoded PHP to generate a big form and populate it with any data you've entered previously, read from the CSV file.

<?php
// Which file is it reading from and writing to?
$filename = "blue.csv";

$fp = fopen($filename,"r");


// Check for problems with the database file.
if (!is_readable($filename)) {
    print "Error: couldn't find the database!";
    exit;
}

if (!is_writeable($filename)) {

    print "Error: the database isn't writeable!";
    exit;
}

$array = file($filename);

foreach($array as $row) {
    $line = explode("|", $row);

}

// The form, as many as you want to put in the array (eg. $line[55] or $line[99]).
print "<form action=addblue.php method=post name=add>
        <input name='a1' 'text' id='a1' value='" .$line[0]." '>
        <input name='a2' 'text' id='a2' value='" .$line[1]." '>
        <input submit name=Submit value=Submit>
        </input></input></input></form>";


fclose($fp);

?>


2. That submits to another PHP file containing this:

<?php
// Define our file name.
$filename = "blue.csv";


// Check for problems with the database file.
if (!is_readable($filename)) {
    print "Error: couldn't find the database!";
    exit;
}

if (!is_writeable($filename)) {

    print "Error: the database isn't writeable!";
    exit;
}

// Open the file for writing.
$fp = fopen($filename,"w");


if (!$fp) {
    print "Error: can't write to the database!";
    exit;
}

// What is being written?
$stringtowrite=$a1."|".$a2."\n";


// If the form has been submitted, do things, otherwise display the form.
if ($Submit) {
    fwrite($fp, $stringtowrite);
    print "Success. Your update is in the database.<a href=blue.php>Click here to go back to the form.</a>";
    //readfile($filename);

    } else {
    print "Nothing to do.";
}

fclose($fp);?>


3. And this is the bit for public consumption, this just reads the guff out of the CSV file, you'll need a bunch of HTML in here.


<?php

// Define our file name.
$filename = "blue.csv";
$fp = fopen($filename,"a+");

// Check for problems with the database file.
if (!is_readable($filename)) {

    print "Error: couldn't find the database!";
    exit;
}

if (!is_writeable($filename)) {
    print "Error: the database isn't writeable!";

    exit;
}

$array = file($filename);

foreach($array as $row) {
    $line = explode("|", $row);
    print "Team 1: ".$line[0]." Team 2: ".$line[1]." etc.";

}

?>



Now, I used this for tennis draws with stupid-many results, in waaay too many columns and rows and it worked okay. I suggest that your admin page for each draw (looks like gold and blue) look really much the same as the public page, but of course the admin page has a huge form with input fields where on the public page it just prints some text into a table cell.

Don't know how well the code will show up - looks like you'll need to add a '<?php' bit at the beginning of each code chunk, and those form fields might be rendered rather than just displaying the code, so perhaps you should look at the source of this page.

Oh, and make sure the admin pages are in a password protected sub-folder (I just used htaccess), and your .csv files (I've replaced the original with 'blue.csv' in my code examples, but you'll also want one called gold.csv or something) will need to be writeable by the server too, I guess.


Good luck.
posted by Khalad at 6:33 AM on February 1, 2006


« Older Is 200 pounds of dog just nuts?   |   35 wireless mice- rechargable or not? Newer »
This thread is closed to new comments.