MYSQL错误而不是null仍然向mysql添加数据

Hi I have a piece of code I am trying to use to populate a new database table. The problem I am having is that i am getting the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'N TENSION')' at line 2

The second problem is that the code inserts all entries and not just the ones where the field search_term has a value

my code is here

 $query = "SELECT * FROM vistordetails1 WHERE search_term IS NOT NULL";      
 $result = mysql_query($query) or die(mysql_error());
 while($row = mysql_fetch_array($result)){

$search_term =$row['search_term'];
    $client_id =$row['client_id'];


     mysql_query("INSERT INTO google1 
     (client_id, term) VALUES('$client_id', '$search_term') ") 
                   or die(mysql_error());  

          }

You can do everything with a single query:

INSERT INTO google1 (client_id, term)
SELECT client_id, search_term
FROM vistordetails1
WHERE search_term IS NOT NULL
      AND search_term <> ''

(anyway, the problem is that probably you have a term that contains a ', and it is not correctly escaped)