PHP OOP NOT ADDING

983

Im trying to create a to-do list following a tutorial from phpacademy. Iv managed to get everything to work, accept for submitting the user input into the database. This is my code so far.

<?php

require 'init.php';

if(isset($_POST['submit'])){
    $name = trim($_POST['name']);

    if(!empty($name)) {
        $query = $db->prepare("
            INERT INTO items (name,done) VALUES (:name,0)
            ");

        $query->execute([
            'name' => $name
            ]);
     }
}
else {
    echo ' not submitted';
} ?>
441

Answer

Solution:

Try this way to fix your typoINSERT and:name

<?php
require 'init.php';

if(isset($_POST['submit']))
{
  $name = trim($_POST['name']);
  if(!empty($name))
   {
    $query = $db->prepare("
        INSERT INTO items (name,done) VALUES (:name,0)
        ");
    $query->execute([
        ':name' => $name
        ]);
   echo "Successfully Inserted";
   }

} 
else{
  echo ' not submitted';
 }
?>

People are also looking for solutions to the problem: php - How to determine columns that will be returned in the result when using `paginate()` method in Laravel?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.