Hi Gang,
How would I go about checking to see if an exact 'product name' exists in my DB before writing the row?
Is that the DISTINCT SQL function?
TIA Will.
Duplication Advice : Records into MySQL
Moderator: General Moderators
Code: Select all
SELECT DISTINCT column FROM tableTo catch Mysql errors in PHP, use the mysql_error() function 

That's of course the most simplistic and not the most secure method of error handling, but gives you the idea and is ideal for development
Code: Select all
<?php
mysql_query("ALTER TABLE tableName ADD UNIQUE (columnName)") or die(mysql_error());
?>That's of course the most simplistic and not the most secure method of error handling, but gives you the idea and is ideal for development
Code: Select all
$stmt = "insert into tablename values('" . mysql_real_escape_string($_POST['something']) . "')";
if(!mysql_query($stmt)) {
if( preg_match("/duplicate entry/i", mysql_error()) ) {
// there was attempt to insert duplicate record, do something (redirect, etc)
}
} else {
// entry inserted successfully
}I think we may be crossing paths.
I've altered the MySQL column parameters ok (ALTER - ADD UNIQUE etc)
Now i'm adding data into that table/column with the INSERT below and the error displays on the browser :
Duplicate entry 'Wills Test' for key 2
So how would I add a link to 'back' or use an js alert and once OK is clicked go back to the form.
thanks for the assitance Jenk 
I've altered the MySQL column parameters ok (ALTER - ADD UNIQUE etc)
Now i'm adding data into that table/column with the INSERT below and the error displays on the browser :
Duplicate entry 'Wills Test' for key 2
So how would I add a link to 'back' or use an js alert and once OK is clicked go back to the form.
Code: Select all
$sql_add = "INSERT INTO ausapapersummary values ('','$paperCategoryId','$colloPaperName','$manufacturerName','$cpl','$stockId','$adhesiveId','$linerId','$supplierId','$availability', '$features', '$limitations','$productExamples','$suitabilityFoil','$suitabilityYellowLight','$suitabilityLabel','$suitabilityOpacity','$suitabilityBronze','$suitabilityScreen','$suitabilityIceBucket',now(),'')";
from this :
mysql_query($sql_add) or die(mysql_error());
to this :
mysql_query("ALTER TABLE ausapapersummary ADD UNIQUE (colloPaperName)") or die(mysql_error());