are you using php artisan serve?
Jul 4, 2019
4
Level 1
curl : Failed to store data in DB
Using curl in my project first time. Trying to generate curl request to register user but data is not stored in my database.
The code to make curl request after form submission:
web.php file
Route::post('/submit-form', 'Auth\RegisterController@postRequest')->name('submit-form');
public function postRequest(){
$data = ['Name'=>'abc', 'Email'=>'[email protected]'];
$url = 'http://localhost/myproject/public/index.php/postReqFromView';
try{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
print_r($server_output);
}
catch (\Exception $exp){
print_r($exp->getMessage());
}
}
The following controller is in my other project where I am trying to receive the request and process it
api.php file
Route::post('/postReqFromView', 'studentRegisterController@postRequest');
my controller
public function postRequest(Request $request){
$abc = DB::table('tbl_users')->insert(['username' => $request->Name, 'email' => $request->Email]);
return $abc ;
}
Please help me out
Please or to participate in this conversation.