Ok so first of all, WHY ARE YOU OPTIMIZING THE TABLES SO MUCH!?!
In reality, you should rarely IF EVER need to use OPTIMIZE TABLE, and you DEFINITALLY SHOULD NOT BE USING IT AFTER EVERY DELETE QUERY!
It locks the tables which will cause problems if you run it too much on large tables, and theres really no need to use it unless you make A LOT of changes to the table ( ie 2,000 delete statements, not 1 )
:-P
BUT... anyway...
You arn't even calling the functions, because for some strange reason you have the function calls surrounded in double quotes, which makes them a string, not a function call.
Use this:
$delete = "DELETE from members where memID = '$q' ";
$result = mysql_query($delete);
$deleted = mysql_affected_rows($result);
$opt = "OPTIMIZE TABLE members";
$opt_table = mysql_query($opt);
Also, start using:
mysql_query ("your query here") or die (mysql_error());
So you can see your errors as well!