This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

vincent.van.wijk10823
vincent.van.wijk10823

Hi, I'm trying to insert some data submitted on a form into my database, the problem is, that the function runs 3 times for some reason, so it inserts 3 the same record into the db. i also tried with just an empty form and a submit button wich triggers an alert, the alert comes 3 times

heres my code:

<form data-request="onInsert">
             <input type="text" name="naam"></input>
             <input type="text" name="achternaam"></input>
             <input type="text" name="leeftijd"></input>
            <input type="submit" value="add to aan DB"></input>
</form>

function onInsert()
  {
      $naam = post('naam');
      $achternaam = post('achternaam');
      $leeftijd = post('leeftijd');

      Db::insert('insert into test_tabel (naam, achternaam, leeftijd) values (?, ?, ?)', [$naam, $achternaam, $leeftijd]);
   }

Last updated

vincent.van.wijk10823
vincent.van.wijk10823

also how do i get this in a proper code block?

vincent.van.wijk10823
vincent.van.wijk10823

nvm, found the problem; I added a html , head and body tag at the top of the page , which were already in the layout template.

Last updated

Cpt.Meatball
Cpt.Meatball

Why don't you use Eloquent for this?

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.