I've been developing a website and since the beggining I've been thinking of how to solve this problem.
So here it is:
My website as alot of input fields, and with that, I came to notice that if a user uses ' there's an SQL error.
    I've search for similiar problems and i did not find any, but I believe I might be searching the wrong way. 
This is how I execute my queries:
I created a function for my queries:
function query($sql) {  
    $stmt = $conn->prepare($sql);
    $stmt->execute();
}
And then I use it like this:
$sql = "INSERT INTO users(fname,lname,username) VALUES('$fname','$lname','$username')";
$stmt = $dbconn->query($sql); // $dbconn is the variable of my db connection class
I thought about using str_replace to replace the ' with a \ but then if a user uses \ then it will be converted to a ' and it's not that great of a solution.
 
    