2017-01-12 8 views
0

mysqlデータベースのデータの挿入に問題が発生しました。ここで 未定義のメソッドを呼び出すデータベースクエリビルダー:: insertans()

はweb.phpの私のコントローラです:

Route::post('/insertans', '[email protected]'); 

これは、MySQLのための私のPHP関数のコードです:

function insertans(Request $req) { 
     $question1 = $req->input('question1'); 
     $question2 = $req->input('question2'); 
     $question3 = $req->input('question3'); 

     $ans = array("question1"=>$question1,"question2"=>$question2,"question3"=>$question3); 

     DB::table('jawaban')->insertans($ans); 

     echo "Data successfully added"; 
    } 

そして、これは視覚的な目的のために私のhtmlです

<!DOCTYPE html> 
<html> 
<head> 
    <title>PACKET A</title> 
</head> 
<body> 
<form action="/insertans" method="post"> 
     <table> 
      <tr> 
      {{ csrf_field() }} 
       <td>1. &emsp; What does HTTP stands for? </td> 
       &emsp;<td><input type="text" name="question1"></td> 
      </tr> 

      <tr> 

       <td>2. &emsp; What does JS stands for? </td> 
       &emsp;<td><input type="text" name="question2"></td> 
      </tr> 

      <tr> 

       <td>3. &emsp; What does CSS stands for? </td> 
       &emsp;<td><input type="text" name="question3"></td> 
      </tr> 


      <tr> 
       <td><input type="submit" name="submit" value="Submit"></td> 
       <td><input type="reset" name="cls" value="Cancel"></td> 
      </tr> 

     </table> 
    </form> 

</body> 
</html> 
+0

どのようなエラーが表示されますか?問題の詳細をご提供ください。 – Peter4499

答えて

2

Query Builderにはinsertans()メソッドがありません。そのため、エラーが発生します。

おそらくDB::table('jawaban')->insert($ans);代わりに使うinsert()

+0

これで動作します。助けてくれてありがとうxD – darkknight

2

DB::table('jawaban')->insertans($ans);の操作を行うことを意味:クエリを構築するときに

DB::table('jawaban')->insert($ans); 

insertans()は、コントローラのメソッドである、あなたはそれを使用しないでください。

+1

それは今働きます。あなたの助けをありがとうxD – darkknight

関連する問題