I will try to answer all the questions. First question to answer is that your query is not safe. The first example is an example of how you intend to use it, the second how it could be used.
$id = 5;
$query = mysql_query("SELECT * FROM `data` where id=$id");
//the statement sent to mysql:
SELECT * FROM `data` where id=5
But in the following example it shows that your code is not safe:
$id = "5; DELETE FROM `data`;";
$query = mysql_query("SELECT * FROM `data` where id=$id");
//the statement sent to mysql:
SELECT * FROM `data` where id=5; DELETE FROM `data`;
It will first search exactly as you wanted it to do, but after that it will totally erase your whole data table.
It seems that it's not safe to use, but there are ways around the above problem. If you first do the sql syntax that require strings as input:
$query = mysql_query("SELECT * FROM `data` where id='$id'");
Then you make sure that you use mysql_escape_string() on everything you get into the webpage:
$id = "5; DELETE FROM `data`;";
$id = mysql_escape_string($id);
$query = mysql_query("SELECT * FROM `data` where id='$id'");
//the statement sent to mysql:
SELECT * FROM `data` where id='5; DELETE FROM `data`;'
By searching as a string (using the ' signs) you make sure that the above statement is searching for a id that is "5; DELETE FROM data;".
$id = "5'; DELETE FROM `data`;";
$id = mysql_escape_string($id);
$query = mysql_query("SELECT * FROM `data` where id='$id'");
//the statement sent to mysql:
SELECT * FROM `data` where id='5\'; DELETE FROM `data`;'
mysql_escape_string() changes the ' sign to \', and by doing that it makes sure that the database don't read it as a stop of the search. This will make it safe, to my knoledge as safe as it is possible to do in PHP.