-1

i try to update my database but i get error.

i have a table in mysql:

article_id article_title article_content article_timestamp img_url

and in my code :

if(isset($_SESSION['logged_in'])) {
// display add page
if(isset($_POST['title'], $_POST['content'])) {
    $title = $_POST['title'];
    $content = nl2br($_POST['content']); // nl2br - Inserts HTML line breaks 
 before all newlines in a string
    $image = $_POST['image'];
    //$image = "admin/uploads/" . $_FILES['image']['name'];
    $id = $_POST['article_id'];

    if(empty($title) OR empty($content)) {
        $error = 'All fields are required';
    } else {
        **$query = $pdo->prepare("UPDATE articles SET article_title =  $title, 
article_content =  $content, img_url =   $image  WHERE article_id=$id");**
        $query->execute();

        header('Location: index.php');

    }

}
?>

...

i try to write a variable but i get error why?

thank's...

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Do you mean you get the error triggered by if(empty($title) OR empty($content)) or an actual error? If an error thrown by PHP please include it in the post – Steve Nov 16 '18 at 17:57

1 Answers1

1

Though your question is rather unclear, as @Steve suggests what kind of error do you recieve. You are not binding variables after your prepared statement. I suggest reading about Pdo prepare.

A quick example:

$stmt = $pdo->prepare('UPDATE articles SET article_title =  ?, article_content =  ?, img_url = ?  WHERE article_id = ?');
$stmt->execute(array($title, $content, $image, $id));
$user = $stmt->fetch();