I've a VAT TAX TABLE where vats in most of cases have names with percent sign at the end, like:
------------------------------------------
ID | Name | Value |
------------------------------------------
1 | VAT 22% | 22 |
2 | VAT 10% | 10 |
3 | VAT 23% | 23 |
4 | VAT 10% IND-50% | 10 |
------------------------------------------
I have a function that return true if a name is already in use during a new inserting (or modifying a row):
function check_name_exist($id, $name) {
if ( $id == "" ) {
$sql = "SELECT Name FROM tax WHERE Name LIKE ?";
try {
$rs = $db->prepare($sql);
$rs->execute(array($name));
$ris = $rs->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
die($e);
}
} else {
$sql = "SELECT Name FROM tax WHERE Name LIKE ? AND ID <> ?";
try {
$rs = $db->prepare($sql);
$rs->execute(array($name, $id));
$ris = $rs->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
die($e);
}
}
if ( count($ris) > 0 )
return true;
return false;
}
Problem occur when I try to modify ID = 2. It tells me that there is already a row with "VAT 10%". In this case row ID = 4.
But THIS IS AN ERROR.
How can I modify the script to manipulate percent sign passed as char and not as wildcard? (I need to create a universal function also for when i don't have the percent sign in the Name...in general)