Re: Php code in html buttons

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

 



Well, your first problem is that you don't understand the difference between a serverside-script and a client-script.

Here's what happens:
1. A user clicks on a link
2. the browser sends a request for that page to the server
3. the server runs the script
4. the server sends the output of that script to the client
5. the browser takes what it got from the server and shows that as a new page to the user.

When I click a button, the browser needs to send a request for a new page to the server. If you just "paste in" php code into an html tag, you'll have just that: An html tag with some random code "in" it. Will it ever get executed? no. Why not? because it's not on the server, it's at the client.

So, here's what you have to do:
1. create a proper page which makes requests to pages on the server which do what you want 2. make new "pages" on the server which are designed to run the php code you want them to run when the page is viewed.

So, instead of:
<button action='<?php bla bla;?>'>
consider doing:
<button action='script1.php'>
and in script1.php you would do:
<?php bla bla;?>

Hope this clears it all up a bit.

- Tul

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>";
?>

I've got all my variables stored in the php page, and I know they are all
correct. But when I push the button it does nothing. I'm not quite sure what
I am doing wrong.

I have also tried

<input type=button value="Click" OnClick= "<?php
mysqli_query($connect,$query); ?>">

and

<form onclick="<?php mysqli_query($connect,$query); ?>">
<input type=button value="Click">
</form>

Obviously i'm a complete newbie. I'd appreciate any help. Thanks.


--
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