3

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";
       }

    }

my env file goes like this

      APP_ENV=local
      APP_KEY=base64:dpAJ8RO+F4IaiahWWlSUDI9v4nju442zeFEBHmh42XM=
      APP_DEBUG=true
      APP_LOG_LEVEL=debug
      APP_URL=http://localhost

      BROADCAST_DRIVER=log
      CACHE_DRIVER=file
      SESSION_DRIVER=file
      QUEUE_DRIVER=sync

      REDIS_HOST=127.0.0.1
      REDIS_PASSWORD=null
      REDIS_PORT=6379

      MAIL_DRIVER=smtp
      MAIL_HOST=smtp.mailtrap.io
      MAIL_PORT=2525
      MAIL_USERNAME=null
      MAIL_PASSWORD=null
      MAIL_ENCRYPTION=null

      PUSHER_APP_ID=
      PUSHER_APP_KEY=
      PUSHER_APP_SECRET=

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

6

1 Answer 1

3

Everything is fine . Closing the laravel server and again opening it did the trick for me!!!!!!!!! :p)
If you are in such a situation where everything is looking fine then , you must atleast try once closing the laravel server and try again by opening it.

Sign up to request clarification or add additional context in comments.

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.