0
if (isset($_SESSION['logged_in'])) {
if (isset($_POST['title'], $_POST['content'])) {
    $title = $_POST['title'];
    $content = $_POST['content'];

    if (empty($title) or empty($content)) {
        $error = 'All fields are required!';
    } else {
        $query = $pdo->prepare("INSERT INTO articles (atricle_title, atricle_text, atricle_timestamp) VALUES (?, ?, ?)")

        $query->bindValue(1, $title); //error is here
        $query->bindValue(2, $content);
        $query->bindValue(3, time());

        $query->execute();

        header(Location: index.php);
}

Someone knows what's the problem here?. The code itself is more then that, but this is to only relevent part.

Thanks.

4 Answers 4

1
$query = $pdo->prepare("INSERT INTO articles (atricle_title, atricle_text, atricle_timestamp) VALUES (?, ?, ?)")

in this line, the ; is missing

This line is wrong too:

header(Location: index.php);

It has to look like this:

header("location: index.php");
Sign up to request clarification or add additional context in comments.

Comments

1

Missed ; at the end of below line,that's why it's showing error on next line when you are trying to bind value. $query = $pdo->prepare("INSERT INTO articles (atricle_title, atricle_text, atricle_timestamp) VALUES (?, ?, ?)");

and also header(Location: index.php); needs to make parameter as string into header function.

Please try it and me know if any issue.

Comments

0

The error occurs because PHP assumes that the line containing the query hasn't ended, and the next character then violates the syntax rule. Add semi colon ; to the query line.

$query = $pdo->prepare("INSERT INTO articles (atricle_title, atricle_text, atricle_timestamp) VALUES (?, ?, ?)");

Comments

0

You missed a ; in the PDO statement and quotes on the header().

<?php

if (isset($_SESSION['logged_in'])) {
if (isset($_POST['title'], $_POST['content'])) {
    $title = $_POST['title'];
    $content = $_POST['content'];

    if (empty($title) or empty($content)) {
        $error = 'All fields are required!';
    } else {
        $query = $pdo->prepare("INSERT INTO articles (atricle_title, atricle_text, atricle_timestamp) VALUES (?, ?, ?)");

        $query->bindValue(1, $title); //error is here
        $query->bindValue(2, $content);
        $query->bindValue(3, time());

        $query->execute();

        header("Location: index.php");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.