PHP insert ‘ into SQL [duplicate]

Instead of trying to escape the apostrophe, it is much better practice to use prepared statements and binded parameters which will also solve your problem. It solves your problem because you then don’t need to escape the apostrophe (‘):

$type_of_poker = "hold'em no limit";

//binding the parameters to your sql statement
$sql = "INSERT INTO hands (type_of_poker) VALUES (:type_of_poker)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':type_of_poker',$type_of_poker);
$stmt->execute();

Let me know if that worked for you! 🙂

Leave a Comment