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.

akshay
  • 209
  • 1
  • 4
  • 13
  • checked your env file? have you? – f_i Mar 20 '17 at 13:24
  • yeah, according to one of the post on stackoverflow i have deleted DB files from env. – akshay Mar 20 '17 at 13:28
  • http://stackoverflow.com/questions/2972600/no-connection-could-be-made-because-the-target-machine-actively-refused-it and http://stackoverflow.com/questions/28346177/no-connection-could-be-made-because-the-target-machine-actively-refused-it-127-0 and http://stackoverflow.com/questions/9695224/no-connection-could-be-made-because-the-target-machine-actively-refused-it-127-0 – aynber Mar 20 '17 at 13:34
  • May you show for us? – João Mantovani Mar 20 '17 at 13:34
  • you want to look into my env file?? – akshay Mar 20 '17 at 13:36
  • I have added my env file ,please look into it and if their is any error then do let me know. – akshay Mar 20 '17 at 13:46

1 Answers1

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.

akshay
  • 209
  • 1
  • 4
  • 13