I'm using the wamp server but unfortunately, I face a problem that I can't solve. Please someone find the error from my code and tell me How can I solve it?
##While I am trying to get data from the request id by PDO method, I'm getting the following errors##
<?php require_once('header.php'); ?>`
<?php
if (isset($_POST['form1']))
{
$q = $pdo->prepare("UPDATE slider SET
slider_title=?,
slider_subtitle=?,
slider_buttontext=?,
slider_buttonurl=?,
WHERE slider_id=?
");
$q->execute(array(
$_POST['slider_title'],
$_POST['slider_sub_title'],
$_POST['slider_button_text'],
$_POST['slider_button_url'],
$_REQUEST['id']
));
$success_message = "Slider Information Is Updated Successfully";
}
?>
<?php
$q= $pdo->prepare("SELECT * FROM slider WHERE slider_id=?");
$q->execute([$_REQUEST['id']]);
$res= $q->fetchAll();
foreach ($res as $row) {
$slider_title = $row['slider_title'];
$slider_subtitle = $row['slider_subtitle'];
$slider_buttontext = $row['slider_buttontext'];
$slider_buttonurl = $row['slider_buttonurl'];
$slider_photo = $row['slider_img'];
}
?>
The browser output is like the below text
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE slider_id='9'' at line 6 in F:\wamp\www\hotel\admin\slider_edit.php on line 18
CodePudding user response:
don't use comma in last field in sql statment
if (isset($_POST['form1']))
{
$q = $pdo->prepare("UPDATE slider SET
slider_title=?,
slider_subtitle=?,
slider_buttontext=?,
slider_buttonurl=?, // <- here - remove this comma
WHERE slider_id=?