Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ErikRobles's avatar

Default select text getting input into database ::SOLVED::

I am running Laravel 8 and when I select an item from my dropdown, It just chooses the default text from the first option even if it is disabled and storing that in the Database. I am sure I am missing something. Any one can help me with this will be much appreciated. here is one of my select items:

<select name="last_page_viewed[]" type="number" class="form-control" placeholder="Enter page number">
            <option disabled>Please Select a Page</option>
            <option value='Technology Vocabulary'>42</option>
            <option value='Technology Vocabulary'>43</option>
            <option value='Technology Vocabulary'>44</option>
            <option value='Technology Vocabulary'>45</option>
            <option value='Technology Vocabulary, Compound Nouns'>46</option>
            <option value='Relative Clauses - Defining and Non Defining'>
              47
            </option>
            <option value='Briefing'>48</option>
          </select>

In my controller I have the following:

 public function PerformanceAdd() {
        $data['students'] = User::where('teacher_id', Auth::user()->id)->get();
        // get id of level where level_id matches with user_id using model relationship
        $data['levels'] = Level::with('student')->where('id',  'level_id')->get();
        // get list of all exam titles to show on permormance_add view
        $data['exam_titles'] = Oex_exam_master::get()->all();
       
        return view('admin.performance.performance_add', $data);
    }

    public function PerformanceStore(Request $request) {
        $countstudent = count($request->student_id);
        if($countstudent !=NULL) {
            for($i=0; $i < $countstudent; $i++) { 
                $perform = new Performance();
                $perform->teacher_id = Auth::user()->id;
                $perform->date = $request->date;
                $perform->last_unit_covered = $request->last_unit_covered[$i];
                $perform->student_id = $request->student_id[$i];
                $perform->last_page_viewed = $request->last_page_viewed[$i];
                $perform->student_progress = $request->student_progress[$i];
                $perform->exam_type = $request->exam_type[$i];
                $perform->exam_score = $request->exam_score[$i];
                $perform->comments = $request->comments[$i];
                $perform->save();
            }
        } 
        $notification = array(
            'message' => 'Students Performance Successfully Submitted.',
            'alert-type' => 'success'
        );
        return Redirect()->back()->with($notification);
    }

Thanks in advance for any help on this. By the way, all the other data is getting to the db just fine.

EDIT:: I added Value='' and it started working.

0 likes
4 replies
tykus's avatar

Most of the options have the same value; what's going on there?

            <option disabled>Please Select a Page</option>
            <option value='Technology Vocabulary'>42</option>
            <option value='Technology Vocabulary'>43</option>
            <option value='Technology Vocabulary'>44</option>
            <option value='Technology Vocabulary'>45</option>
            <option value='Technology Vocabulary, Compound Nouns'>46</option>
            <option value='Relative Clauses - Defining and Non Defining'>
              47
            </option>
            <option value='Briefing'>48</option>
ErikRobles's avatar

@tykus Thanks for your reply. Yes they have the same value because the student repeated the same topic on a different page. I am in the process of adding a string number to each one to help the person reading the data distinguish all the info. Thank you.

Nakov's avatar

A select does not have a type attribute, so this type="number" does not make sense. And if this last_page_viewed is a number in your database like an integer then you should change your value="" to a number instead of string, if you happen to have 0 for all of the selections.

1 like
ErikRobles's avatar

@Nakov Good Catch, it was a number at one time and then I changed it to string. Now that I know I can change that.

Please or to participate in this conversation.