PHP & Mysqli Code - Is this code safe for a simple search?
It is not safe, you are completely open to SQL Injection. You need to use prepared statements.

Apart from that:


don't use short variables names (q, c, etc)
don't just echo an error, but actually handle it (if there is no db connection, there is no need to execute queries)
try to reduce your nesting, eg by including guard clauses:


Example of guard clauses:

if(!isset($_GET['q']) || $_GET['q'] == ' '){
    // return, die, etc
}

// perform query

if($c == 0){
    // return, die, etc
}

// handle query output