Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Mysql error posting

  • 26-02-2009 10:08PM
    #1
    Registered Users, Registered Users 2 Posts: 3,875 ✭✭✭


    When I try and insert a record into a table via a website, it is at times giving me a duplicate error notice.

    I set this up to avoid duplicates, and I am happy that this is happening

    Is it possible however to show for me to type my own content, instead of the error code been the only thing on the screen?

    I have been searching all over google but have found nothing,
    I must be using the wrong keywords,

    cheers.


Comments

  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    When I try and insert a record into a table via a website, it is at times giving me a duplicate error notice.

    I set this up to avoid duplicates, and I am happy that this is happening

    Is it possible however to show for me to type my own content, instead of the error code been the only thing on the screen?

    I have been searching all over google but have found nothing,
    I must be using the wrong keywords,

    cheers.


    Yup - do a "SELECT" statement before you do the insert, and only run the insert if the number of rows returned is 0.


    SELECT * from TABLE WHERE id=key_id
    :
    if ($numRows==0) {
    INSERT INTO TABLE.....
    } else {
    PREPARE AND SHOW YOUR OWN ERROR MESSAGE
    }


  • Registered Users, Registered Users 2 Posts: 21,278 ✭✭✭✭Eoin


    If MySQL is returning a specific error number, you could also trap this with some try/catch code.


Advertisement