Assuming you are using mysqli to connect to the database, you need to avoid the string using the myqli_real_escape_string () function , otherwise you are at risk of adding sql injection to your application:
executeQuery("select testid from test where testname='" . myqli_real_escape_string($testname) . "';");
I would recommend switching to a parameterized query approach using the prepared statement function that mysqli provides. You can have executeQuery()as follows:
executeQuery("select testid from test where testname=?", $testname)
, .
mysql, mysql_real_escape_string().