I have the following variable grabbing data from HTML:
$workcarriedout = trim($_POST["workcarriedout"]);
And the following statement inserting this entry into SQL database (not a mySQL database):
$stmt = $db->prepare("INSERT INTO [dbo].[server_log_entries] (work_carried_out)
values ('".$workcarriedout."')");
This works perfectly fine until the data entered into the variable contains single quotes.
Could somebody please advise how I can get the data to import with the single quotes?
Edit: If this makes a difference here is the code:
<?php
require_once('../settings.php');
// Get the form fields and remove whitespace
var_dump($_POST);
$datetime = trim($_POST["datetime"]);
$servername = trim($_POST["servername"]);
$carriedoutby = trim($_POST["carriedoutby"]);
$workverifiedby = trim($_POST["workverifiedby"]);
$authorisedby = trim($_POST["authorisedby"]);
$workcarriedout = trim($_POST["workcarriedout"]);
$howverified = trim($_POST["howverified"]);
$reason = trim($_POST["reason"]);
$impact = trim($_POST["impact"]);
$rollback = trim($_POST["rollback"]);
try {
$db = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$stmt = $db->prepare("INSERT INTO [dbo].[server_log_entries] (date_time, server_name, carried_out_by, verified_by, authorised_by, work_carried_out, work_verified, change_reason, perceived_impact, rollback_process)
values ('$datetime','$servername','$carriedoutby','$workverifiedby','$authorisedby','$workcarriedout','$howverified','$reason','$impact','$rollback')");
$stmt->execute();
socket_close($socket);
?>