Adding new row doesnt update the table but updates the database, I explain

Adding new row doesnt update the table but updates the database, I explain

javismilesjavismiles Posts: 205Questions: 38Answers: 3

weird thing happening to me
I got a few tables up and all working great,
now I add a new one with Create, Edit and Delete buttons

When I delete a row, or edit a row, the table updates automatically, all great

it is only when I create a completely new row that it works, no errors, but the table does not update automatically, I have to refresh it myself

I checked network and for some reason the json returned after creating the row is noooot right, its just:
{"data":[]}

that's wrong, but I dont understand why, its same code as previous tables,
and again it only happens with create buttons, edit and delete all good, and also the create action works all fine, when I refresh the new row is there, its just that the return from the create action doesnt return what it should so the table doesnt update

This question has an accepted answers - jump to answer

Answers

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    I went into debug mode

    $editor->debug(true)->process( $_POST );

    and I got this back after creating the row

    {"data":[],"debug":[{"query":"INSERT INTO admin ( user, pass, date, org, id ) VALUES ( :user, :pass, :date, :org, :id )","bindings":[{"name":":user","value":"klkjjkl","type":null},{"name":":pass","value":"e688cc5579a479f5f541f2f0e8803150","type":null},{"name":":date","value":"2018-08-07 21:59:22","type":null},{"name":":org","value":"","type":null},{"name":":id","value":"","type":null}]},{"query":"SELECT id as 'id', user as 'user', pass as 'pass', date as 'date', org as 'org' FROM admin WHERE id = :where_0 ","bindings":[{"name":":where_0","value":"","type":null}]}]}

    u see anything wrong there?

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    i think its not returning the id of the inserted row?

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    i think thats it, but why, its inserting it all well, how weird

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    wowww so weird,
    thats why, it doesnt get the last insert id, but why,
    thats why when i refresh no probs, shows it,
    but why edit and delete work all well, only create fails to bring back the last insert id, wow

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    is it because the table is called admin maybe?
    do you have something with reserved words?

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    no its not that changed database to have a new name and still happens
    soooooooooo weird! only with create, not with edit or delete

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    wow this is one of the weirdest things, Murphy´s law is back,
    just imagine,

    I have two tables in the same database, same type, same all,

    their datatables and editor code is basically the same in front end and back end,
    they both have create, edit and delete buttons

    their code is 99% identical basically, the differences pretty much are the name of the table and of course their fields

    in table A, create, edit and delete buttons work great and instantaneously update the table after executing their actions

    in table B, create, edit and delete buttons work great and edit and delete instantaneously update the table after executing their actions, but create does nottttt and apparently because for some reason its returning empty the inserted id back to the front end (... id = :where_1 ","bindings":[{"name":":where_0","value":"0","type":null},{"name":":where_1","value":"","type":null}]}]})

    really, soooooooo weird,
    any tips?
    thank u

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    they are all in client mode by the way,
    again all the code is exactly the same,
    only difference really is the table name and their fields

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3
    Answer ✓

    wow I solved it,
    so the reason was, in case it can help anybody,

    the only difference between both tables is that in the second table I had also declared the field ID, the id field, in case I would need it for something

    and that's what was preventing the create action from returning the last inserted ID, not sure why thats the case but that was the case,

    I eliminated that and now it all works well,

    however, what If for any reason I do need to get the ID field from the backend to use it in some way, how would I then prevent this problem from happening when creating a new row?

    thank u ;)

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Thanks for posting back - good to hear you have it working now.

    Allan

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    thank u Allan, my only doubt now is : " what If for any reason I do need to get the ID field from the backend to use it in some way, how would I then prevent this problem from happening when creating a new row?"

    so it works all well now, but what If i need a create button in a table where Im getting the ID field of the database as well

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    So you add:

    Field::inst('id')
    

    and it stops working?

    Try:

    Field::inst('id')->set(false)
    

    Allan

  • javismilesjavismiles Posts: 205Questions: 38Answers: 3

    will try thank u Allan

This discussion has been closed.