linda, you need to 'escape' the single quote mark, which means to put a backslash in front of it first. that tells php to treat it as a quote mark, not as the end-of-the-string.
to do this, php has a nice function called 'addslashes' see http://php.net/addslashes
your code would then read
$temp = addslashes($temp);
$sql = "Select * from Tablename where field1='$temp'";
enjoy
Eric