I have a form that inputs data to a database. All is working fine, but what I'd like to do is when it gets to the

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

instead of the mysql_error, I want to display my own error with a link back to the form. Whats happening is that the form inputs an id and this id is my primary key, I want a nicer looking error if a duplicate id is inserted.

Here is the portion of the code I'm dealing with:

$query = "INSERT INTO people (id, fname, lname, phone_num, ext, title, dept, fax) VALUES ('$id', '$fname', '$lname', '$phone_num', '$ext', '$title', '$dept', '$fax')"; 
   $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
    echo "New record inserted with ID ".mysql_insert_id();
    echo '<br /><a href="phone_maint.php">Return to Maintenance Form</a>';

Do I need an IF statement in this area?


Ok, i found a solution, I don't know if its the correct way to do it, but it works for me.


This question has already been answered. Start a new discussion instead.