// inserting into DB from form
if (!empty($_POST['Title'])) {
$t = mysqli_real_escape_string($dbc, ($_POST['Title']));
} else {
$errors[] = 'Please enter a Headline title';
}
// Add the news to the database:
$q = 'INSERT INTO news ( Title, Content) VALUES (?, ?)';
$stmt = mysqli_prepare($dbc, $q);
mysqli_stmt_bind_param($stmt, 'ss', $t, $c);
mysqli_stmt_execute($stmt);
If the $t contains an apostrophe e.g
We're awesome
it will add it to the DB as
"we\'re awesome"
later on:
How do I then run a query where title = $t
$q = "SELECT * FROM news WHERE title= '$t'";
The query fails because apostrophe cuts the SQL off effectively
SELECT * FROM news WHERE title = ' we're awesome