mardi 3 septembre 2019

I am trying to Post data into my database using PHP & SQL

I am trying to post data inputted by an admin into the database. I have 2 inputs which are is a text input and a text area. However, when I submit the form uploadscript.php comes up with an error. I should also be redirected to home.php however this does also not work. However I think that not being directed to home.php is something to do with the error I have received.

I have used similar code for my register system on the website and it works fine, however this time it does not.

if(!isset($error)){
    try{
        $stmt = $con->prepare('INSERT INTO blog (title,blog, date) VALUES (title-box, , blog-box, :postDate)');
        $stmt->execute(array(
            'title-box' => $title,
            'blog-box' => $blog,
            ':postDate' => date('Y-m-d H:i:s')
            ));
        header('Location: home.php?action=added');
        exit;
    } catch(PDOException $e){
        echo $e->getMessage();
    }

}


I expect that when the form is submitted that it should add the data inputted by the user into the database, however it keeps coming up with this error.

Fatal error: Uncaught Error: Call to a member function execute() on bool in C:\xampp\htdocs\phplogin\uploadscript.php:25 Stack trace: #0 {main} thrown in C:\xampp\htdocs\phplogin\uploadscript.php on line 25

Line 25 is ($stmt->execute(array(




Aucun commentaire:

Enregistrer un commentaire