Your second snippet is interesting. Normally, you would want to check that the form is posted before doing an insert. I've done that, and converted your DB calls to mysqli_* and made a few comments you might wish to think about/investigate:
<?php
if (!$_POST) {
?>
<form action='#' method='post'>
<table cellspacing='5' align='center' border ='1'>
<tr><td>Member_ID:</td><td><input type='text' name='member_ID'/></td></tr>
<tr><td>Class number:</td><td><input type='txt' name='Class_no'/></td></tr>
<tr><td></td><td><input type='submit' name='Book' value='Book'/></td></tr>
</table>
</form>
<?php
} else {
$username = "root";
$password = "";
$database= "Mygym";
$member_ID=$_POST['member_ID'];
$class_no=$_POST['Class_no'];
// You probably should do some checking on the above. For example, should the member_ID be numeric?
// What if someone puts an word in there? An *evil* SQL statement in there? If both of these are numeric,
// the solution *might* be as simple as checking with intval() and an integer, or perhaps with is_numeric().
$db_conn = mysqli_connect("localhost",$username,$password,$database);
if (!$db_conn) { //problem with DB connection or selection
die("DB Problem"); //much better would be a legitimate error-handling routine ;-)
}
$query="insert into book values ('$member_ID', '$class_no') ";
mysqli_query($db_conn,$query); //once again, you're not testing for success. Should your program
//give the user some feedback if the query fails? What about a success message?
mysqli_close($db_conn);
}
?>