I know this has been asked many times before but I'm still stumped. I'm obviously missing something but I have been unable to figure out how to successfully escape the apostrophe when sending a mysql query from php. Why does this not work when everything I have read says it should.
<?php
$title = "havin' fun";
$con=mysqli_connect($server,$username,$password,$database);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$title = mysqli_real_escape_string($title);
$result = mysqli_query($con,"SELECT id,artist,title FROM songs WHERE title = '$title'");
if($result) {
while($row = mysqli_fetch_assoc($result)) {
$id = $row['id'];
$artist = $row['artist'];
$title = $row['title'];
echo $id.' - '.$artist.' - '.$title.'<br>';
}
}else echo 'No Results';
mysqli_close($mysqli);
?>