handling duplicate records in mysql Insert statement

前端 未结 4 1842
被撕碎了的回忆
被撕碎了的回忆 2021-01-26 10:59

Im i have a php form to enter data into a mysql database, my question is how do i handle duplicate records for example if an ID number already exsists how do i check if exsists

4条回答
  •  情歌与酒
    2021-01-26 11:42

    eigther check before inserting or do and update.

    check

    "SELECT COUNT(*) FROM loan WHERE loan_id = '" . $values['load_id'] . "'"
    

    update

    "INSERT INTO loan (loan_id, some_field) VALUES ('". $values['loan_id'] ."', '". $values['some_field'] ."') ON DUPLICATE KEY UPDATE some_field = VALUES(some_field)";
    

提交回复
热议问题