View Full Version : php in html

06-10-2005, 10:15 AM
trying to execute a simple php function from html button onclick

function DBConnect(){

echo "Test msg<br>";

//will add sql functions here when it works first


<input name="Button" type="button" onClick="<?php DBConnect(); ?>" value="Button">

whats wrong?

06-10-2005, 12:40 PM
In order for any server side script to be executed one of the following must happen

1. Page must be reloaded
2. A form has be be submitted


The code above has been delivered on the clients machine.
The code can be executed on your server that can understand PHP

So what u can do is this:

1. OnClick run a javascript to reload the page (top.location.href) passing a quertstring. so when the page reloads the url is something like this http://www.somewhere.com/connect.php?connect=clicked ('http://www.somewhere.com/connect.php?connect=clicked')

2. When page loads check(with PHP) if connect = clicked. If its click connect to db, if its null do nothing

06-14-2005, 01:29 AM
thanks. Had a friend help with details and got it working.