I'm relatively new to using mysqli prepared statements and am having problems inserting strings that contain forward slashes.
Here's an example of the code I'm using:
// $mysqli connection
$rxcui = null;
$name = null;
$synonym = null;
$tty = null;
$sql = "INSERT INTO fda_oral (id, rxcui, `name`, `synonym`, tty, hide, created, updated) VALUES (NULL, ?, ?, ?, ?, 0, NOW(), NOW() )";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("ssss", $rxcui, $name, $synonym, $tty);
$rxcui = "201903";
$name = "acyclovir 40 MG/ML Oral Suspension [Zovirax]";
$synonym = "Zovirax 40 MG/ML Oral Suspension";
$tty = "SBD";
if ($stmt->execute()) {
echo "success";
} else {
echo "failed";
}
This is failing.
If I use stings without the slashes I am successful, eg)
$name = "acyclovir 400 MG [Zovirax]";
$synonym = "Zovirax 400 MG Oral Suspension";
From everything I've read, it sounds as if the prepared statements should deal with any special characters in the strings - in fact, it seems like this is the recommended solution when dealing with strings that might have special characters.
Even though it doesn't seem like it should be necessary, I did try
$name = $mysqli->real_escape_string($name);
I'm sure I'm missing something simple here but I just can't figure out where I'm going wrong.