NYCPHP Meetup

NYPHP.org

[nycphp-talk] Help with Buttons and how I can only make pressable once a day

michael lists at genoverly.net
Mon Jul 3 07:37:42 EDT 2006


On Mon, 3 Jul 2006 03:47:00 -0700 (PDT)
Karl Brian Dano <karl_niarb at yahoo.com> wrote:

> Hi everyone,
> 
> Again, I need some help with PHP/MySQL. How do I assign a MySQL query
> to a button and how can make the button only pressable (or be
> available for "pressing") once a day?
> 
> Help will be greatly appreciated.

A button click in PHP (in the browser) does not send a signal like a
button click event in a gui desktop application (vb, WXWindows, qt, gtk,
tkinter, etc).  First you need an HTML form element and an input
element.  Each will have characteristics that tell the web server what
to do.  Here's some samples, spaced for easy reading:
  
<form 	name="form_page" 
	enctype="multipart/form-data" 
	action="./"
	method="post">

<input	type="submit" 
	name="btn_runquery" 
	value="Submit">

In the above case, your code needs to check the value of the button:
	if ( isset($_POST["btn_runquery"]) ) { // do stuff }

You can read up on HTML forms and other elements here:
http://www.w3.org/TR/html4/interact/forms.html

As for making it 'pressable' on a schedule.. you could 
1) always have the button available, but have the 'do stuff' check to
see if it is OK to run before it executes. 
2) have a 'button creating routine' that checks to see if it is OK to
run and either enable or disable the button whenever the form is
visited.

One idea that would work for either option.. have touching a file on
the file system the last thing in the 'do stuff' event. Then, the next
time the form is visited, your 'do stuff' or 'button creating routine'
can check the date on that touched file. If it already has today's date,
then do nothing (or disable button).  If it has yesterday's date; do
the event, and touch the file again (which gives it a new date).  It
doesn't have to be a file, it could be a record in the database.. or
anything persistent.

This is a really basic programming situation.  You might be a good
candidate for a NYPHP Training class (http://www.nyphp.com/training/).


-- 

Michael



More information about the talk mailing list