Re: Php code in html buttons

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi k,

Tuesday, July 10, 2007, 11:59:42 PM, you 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>";
?>>

Everything about this approach is wrong.

PHP is a *server side* language, not client-side.

An onclick is a client-side event. The PHP cannot be re-parsed and
acted upon when you hit onclick in the way you are trying to do.

You can either make the page reload (or go to another page) which runs
the results of the button click, or you can perform some Ajax wizardry
in the onclick event to call a remote PHP script and suck the results
back into your current page.

To be honest I'd start by reading any of the stacks of online
PHP beginners tutorials out there before touching another line of code
on this path.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux