Reputation: 1212
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)
{
});
}
Upvotes: 0
Views: 318
Reputation: 33048
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.
Upvotes: 1