View Single Post
  #8 (permalink)  
Old 11-03-2009, 01:46 AM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,900
wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10
Default Re: PHP, check if a record was inserted via MySQL...

Another (tricky) way to do it is to get the insert id of the newly created record, assuming you are entering a new row into the database. This can be used in two ways - to confirm that the row was created successfully, and to perform additional work on the entry or to link other tables to the new entry. The function, run after the insert query, is mysql_insert_id(), which will return 0 if no new id was created. You can get more info and some samples here: PHP: mysql_insert_id - Manual

Another good method, which I often use, is to simply test if an error has been set. If the error id is 0, the previous command executed correctly, otherwise call the error handler... if (mysql_errno()) echo mysql_error;
__________________
The best way to learn anything, is to question everything.
WigeDev - Freelance web and software development

Last edited by wige; 11-03-2009 at 01:50 AM.
Reply With Quote