Question
I'm getting an error in my code and need help solving it. Fatal error: Uncaught Error: Call to undefined method PDO::real_escape_string() in C:Program FilesAmppswwwbookstore-labs-arbiter1170submit_review.php:45 Stack
I'm getting an error in my code and need help solving it. Fatal error: Uncaught Error: Call to undefined method PDO::real_escape_string() in C:\Program Files\Ampps\www\bookstore-labs-arbiter1170\submit_review.php:45 Stack trace: #0 C:\Program Files\Ampps\www\bookstore-labs-franko44\submit_review.php(20): sanitizeString() #1 {main} thrown in C:\Program Files\Ampps\www\bookstore-labs-franko44\submit_review.php on line 45.
How can I fix my code?
Also, how can I add a button that returns the user to "review.php" after they've submitted a review?
Here is my code, in the file called "submit_review".
require_once("login.php");
require_once("books.php");
require_once("review.php");
function mysql_entities_fix_string($pdo, $string)
{
return htmlentities(mysql_fix_string($pdo, $string));
}
function mysql_fix_string($pdo, $string)
{
if (get_magic_quotes_gpc()) $string = stripslashes($string); // stackoverflow clutch for this :D
return $pdo->real_escape_string($string);
}
if(isset($_POST['submit'])) {
$bookID = isset($_POST['book']) ? sanitizeString($_POST['book']) : null;
$rating = isset($_POST['rating']) ? sanitizeString($_POST['rating']) : null;
$review = isset($_POST['review']) ? sanitizeString($_POST['review']) : null;
if(empty($review)) {
$review = null;
}
$stmt = $pdo->prepare("INSERT INTO reviews (BookID, Rating, Review) VALUES (?, ?, ?)");
$stmt->bindParam(1, $bookID);
$stmt->bindParam(2, $rating);
$stmt->bindParam(3, $review);
$stmt->execute();
header("Location: review.php");
exit();
}
function sanitizeString($var) {
global $pdo;
$var = strip_tags($var);
$var = htmlentities($var);
if (get_magic_quotes_gpc()) {
$var = stripslashes($var);
}
return $pdo->real_escape_string($var);
}
?>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started