Re: Php code in html buttons
| From: | Richard Lynch | Date: | Wed, 11 Jul 2007 21:24:03 +0000 |
| Subject: | Re: Php code in html buttons | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258649@lists.php.net to get a copy of this message | ||
On Tue, July 10, 2007 5:59 pm, k w wrote:
> I'm trying to make a button execute some php code when the button is
> clicked. I'm not sure if it is the button i'm coding wrong or the php
> code.
> Here is the code I am using.
>
> <?php
> echo "<button action='<?php
> mysqli_query($connect,$query)?>'Click</button>";
> ?>
[sportscaster voice-over]
Joe: Hey Bob, let's look at a slow-motion instant-replay of this
common PHP newbie fallacy scenario
Bob: Sure Joe!
Joe: Okay, so here goes:
The user requests a HTTP URL document.
The webserver fires up.
The webserver finds that it needs PHP to generate the document.
PHP fires up.
Bob: Wow, look at it go! That's fast!
Joe: Yeah, it is fast.
PHP has generated the document, and spits it out.
Bob: Boy, it's already finished. Hey, it's quit!
Joe: That's right, Bob.
PHP has FINISHED EXECUTION, and has exited.
Now watch this!
Bob: Oh boy, I see it coming now...
Joe: Yep, there it is.
There's some HTML in the browser, trying to execute some PHP code...
Bob: But you can see, PHP has LONG FINISHED and is OUTTA HERE!!!
Joe: That's right, Bob, PHP is simply not around to execute that code.
Bob: So what can you do, Joe?
Joe: Well, if you can live with the browser going back-n-forth to the
web-server, with a significant "lag" time...
Bob: Oooh, well, I can see how that might be useful sometimes...
Joe: In those cases, you can use Ajax.
Bob: Anything else?
Joe: Not really. Until you get back to the webserver and PHP, there's
just no PHP available. Unless your user is in the extreme minority of
uber-PHP-geeks that has installed this EXPERIMENTAL PHP browser
plug-in thingie: http://pecl.php.net/package/PHPScript
Bob: Whoa, Joe, I don't think I've ever even heard of anybody who's
ever installed that.
Joe: Me neither, though I met Wez Furlong who wrote it, so I have to
assume HE has installed it at least once...
[cue to cool Guinness commercial]
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?