0

I want to put a question(text) into my database. The table is put into the database with the ID and time of creating it, but the question(text) is still empty.

(don't notice the Question1/2/3/4, these are not made into the database yet, so it is just about the "Quiz Name")

Here is my code :

 public function postCreate() { $validator = Validator::make(Input::all(), Quiz::$rules); if($validator->passes()) { $quiz = new Quiz; $quiz->quizname = Input::get('quizname'); $quiz->save(); return Redirect::to('quizzes')->with('message', 'Your quiz has been created!'); } 

 {{ Form::open(array('url'=>'quizzes/create', 'class' => 'createquiz')) }} <h2>Create a Quiz now!</h2> <p>Quiz Name</p>{{ Form::text('quizname', null, array('required')) }} <p>Question 1</p>{{ Form::text('quizname', null, array('placeholder' => 'Question 1', 'size' => '40')) }} <p>Question 2</p>{{ Form::text('quizname', null, array('placeholder' => 'Question 2', 'size' => '40')) }} <p>Question 3</p>{{ Form::text('quizname', null, array('placeholder' => 'Question 3', 'size' => '40')) }} <p>Question 4</p>{{ Form::text('quizname', null, array('placeholder' => 'Question 4', 'size' => '40')) }} <br> <br> {{ Form::button('Add Question') }} {{ Form::submit('Create') }} {{ Form::close() }} 

 public function up() { Schema::create('quizzes', function($table) { $table->increments('id'); $table->string('quizname'); $table->date('created_at'); $table->dateTime('updated_at'); }); Schema::table('quizzes', function($table) { }); } 
1
  • use var_dump(Input::get('quizname')); to see if you are getting the input. If thats empty, thats the stem of your problem. It is most likely related to what @user3158900 mentions. Commented Mar 20, 2015 at 13:23

1 Answer 1

1

All your inputs should have different names. The problem is because you are naming everything quizname. I'd suggest giving your questions the name question[] so that you can loop through them and easily create them later.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.