简体   繁体   中英

PHP on Submit check for records, if record exist 'confirm' update or insert new if no record

I am having trouble figuring out how to correctly execute the following problem. I have a web form that my user will fill out, this form has (ajax that populates the account user will work with aka admin).

Before submission of the new data I would like to verify if that account already has data, if data exists I need to have a confirmation to override the current data. If there is no data nothing happens (new data just gets inserted into the db).

This is the flow of the page,

1) (Ajax) Input -> Find account, 2) Once account selected enter data (no refresh between the two steps) 3) Submit data -> Still on same page (looking if Input Exists and executes Insert)

Is it possible to have some sort of confirmation inside the try / catch before submission.

Code:

if(Input::exists()){
    try{
       if(row exists){
        // Confirm here if row exists to override or cancel SUBMIT
       }else{ // insert new }

Why I need this is because accounts are allowed to have only 1 of this kind of record, and I don't want them to accidentally override existing record (if it exists).

Thanks

I have managed to solve it, what I did was onclick of account that would fill the INPUT BOX; I would than use ajax to check for the rows of selected account. If row was found I would ask for confirmation using jQuery confirm and if clicked OK I would populate HIDDEN input with value 1 . So on submit it would check if the hidden field is 1 or 0 if 1 that would mean its an update of existing record and if 0 it would create new one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM