I'm new to php. I have a function in php which when executed returns results from the database. When i'm using this function in my html page with the onclick method it is not working. Can you please help me out? Below is the code for the page author.php which contains the function-
<?php
function author_list()
{
global $con;
$con=mysqli_connect("localhost","root","","project");
if(mysqli_connect_errno())
{
echo "failed to connect".mysqli_connect_errno();
}
$author=mysqli_query($con,"select * from english where author='".$SBA."' ");
echo"<table>";
while($data=mysqli_fetch_array($author))
{
echo"<tr>";
echo"<td>".$data['genre'];
echo"<td>".$data['author'];
echo"<td>".$data['title'];
echo"<td>".$data['year'];
echo"<td>".$data['avail'];
}
echo"</table>";
mysqli_close($con);
}
?>
below is the part of the code of the html page where i have to set the above function on onclick:
<form action="author.php" method=GET>
Search By Author:<input type="text" name="SBA" value=""><br>
<input type="submit" value="submit" onclick= "author_list()">
It is just printing the "while loop" part of the function as it is, on the page. I am also allowed to use javascript(if that helps). Can you please help me out?