PDA

View Full Version : php in html


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





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

ranjan
06-10-2005, 01: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

Why?

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

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