Insert adds many entries instead of only one?

Posted 6 months ago by uccdev

I'm interfacing with a database in my Laravel controller, where I want to insert given data into a database.

My insert statement is like this:

  $insert =
      'id'  => $data['id'],
      'forename'    => $data['forename'],
      'surname'     => $data['surname'],
      'course'   => $data['course'],
      'status'   => $data['status'],
      'photo'       => $data['photo']

This should create only one insertion, to the best of my understanding, since I am only entering the one value. However, when the page tries to display the results when I search based on ID alone, I get dozens and dozens of entries! One for each combination of "course" and "status" (where those two are fixed fields, values between 1 and 5).

Note that I am not working with a model, just putting the input straight into a controller.

I have also tried the alternative laravel function, DB::insert...

  $insert = DB::insert("INSERT INTO myTable
  (id, forename, surname, course, photo)
  VALUES (?, ?, ?, ?, ?)", [$data['id'], $data['forename'], $data['surname'], $data['course'], $data['status']]

...But this runs into the same problem.

Furthermore, when I check my database separately (via a "SELECT * FROM myTable WHERE id = 888;") then I don't get many entries - I get only one.

Yet my webpage shows as many as 40 entries for that same ID, for a single iteration of a given field - when only one should exist at all.

Any advice? I'd be most grateful for any help someone could give me here.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.