I have a file named a.php which has a html button with a script function within the same page.Code is given bellow
//a.php
<input name="wpost" type="button" value="Publish" onClick="wall_publish()"/>
<script type="text/javascript">
function wall_publish(){
//some codes here..
//php database part
<?php
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'uploader';
$con = mysql_connect($host,$username,$password);
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $con);
mysql_query("UPDATE image_uploader SET Tag_Count = '$tag_count', Tag_List = '$tag_list' WHERE Image_Link = '$source'");
mysql_close($con);
?>
}
</script>
I want to execute the php database part when the user click the "Publish" button(Not when the page is loaded).,
Is there a way to do this?
Just placing this php code inside the script function doesn't work.It is executed when the page is loaded.