0

Im calling this controller method from a search field. I need to check wether the entered value exists in city, state or zip fields in the database. But I'm getting the above error. How to resolve this?

  public function search_x(Request $request)
{
    $value = $request->input('search_daycare_zip');

    $data1 = DB::select('SELECT * FROM daycares WHERE city = '.$value.'');
    $data2 = DB::select('SELECT * FROM daycares WHERE state = '.$value.'');
    $data3 = DB::select('SELECT * FROM daycares WHERE zip = '.$value.'');

    if($data1 != null){
        return view('daycare.daycares')->with('daycares',$data1); 
    }else if($data2 != null){
        return view('daycare.daycares')->with('daycares',$data2); 
    }else if($data3 != null){
        return view('daycare.daycares')->with('daycares',$data3); 
    }else{
        return view('daycare.no_daycare');
    }
    // return 'done';
}enter code here
harinsamaranayake
  • 751
  • 2
  • 12
  • 32

1 Answers1

0

As TsaiKoga said, your Code is vulnerable for SQL injections and the usage of a proper SQL builder should be prefered. Besides that - i guess you are missing " around your value in the SQL string.

Andy May
  • 1
  • 3