Monday, March 20, 2017

Error in inserting into sqlite database through laravel php

I am trying to insert values into sqlite database through a view which has form in it. This view calls the insert method inside Task_controller class ,which results into the following error

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: insert into task (Title, Completed, Description, created_at, updated_at) values (kfjjklsjfl, bnm, mnm, 2017-03-20 12:57:31, 2017-03-20 12:57:31))

But when i insert row into table using "php artisan tinker" ,then their is no error.

my create_task.blade.php file goes like this , it has form html code in it

    <!DOCTYPE html>
    <html>
    <body>
    <h1>Create Task</h1>
    <form action="/insert">
    Title:<br>
    <input type="text" name="Title">
    <br>
    Completed:<br>
    <input type="text" name="Completed">
    <br>
    Description:<br>
    <input type="text" name="Description">
    <br><br>
    <input type="submit" value="Submit">
    </form> 

    </body>
    </html>

my route file goes like this

    Route::get('/', function () {
          return view('task');
    });

    Route::get('/create_task', function () {
         return view('create_task');
    });

    Route::get('/decide', "Task_Controller@decide");

    Route::get('/insert', "Task_Controller@insert");

and my controller file goes like this.

     <?php

     namespace App\Http\Controllers;

     use DB;
     use DateTime;
     use Illuminate\Http\Request;
     use Illuminate\Support\Facades\Input;

     class Task_Controller extends Controller
     {

     public function insert()
     {
           $Title = Input::get('Title');
           $Completed = Input::get('Completed');
           $Description = Input::get('Description');
           $insert=DB::table('task')->insert(['Title' => $Title,'Completed' => $Completed,'Description'=> $Description,'created_at' => new DateTime ,'updated_at'=>new DateTime]);
          if($insert)
               echo"Successfully inserted";
          else
               echo "error";
       }

    }

Please help I'm not able to figure out , why this error is coming.



via akshay

Advertisement