Answer the question
In order to leave comments, you need to log in
Escaping for DB?
Hello.
My problem is this:
English sentences have an apostrophe, so they need to be escaped for the database. This code does not work (nothing is written to the database), but if you remove the mysql_real_escape_string function, everything is written, except for those sentences that contain apostrophes. Where did I go wrong?
<?php
include('db.php');
$dataJSON = $_POST['data'];
$arrData = json_decode($dataJSON, true);
for($i = 0; $i < count($arrData); $i++) {
for($j = 0; $j < count($arrData[$i]); $j++) {
$english_sentence = mysql_real_escape_string( $arrData[$i]['english-sentence'] );
$russian_sentence = mysql_real_escape_string( $arrData[$i]['russian-sentence'] );
}
mysqli_query($connection, "INSERT INTO `words` (`english-sentence`, `russian-sentence`) VALUES ('$english_sentence', '$russian_sentence')");
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question