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>';
     
    mysql_close($connection);

Do I need an IF statement in this area?

thanks,

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

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.