Hardist
07-15-2012, 09:38 AM
Hey guys,
How would I check if something is already in the database, when trying to post something. I have the following database:
CREATE TABLE `doc_items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(75) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
I am using the following code to check if a value already exists:
$result = mysql_query("SELECT name FROM doc_items WHERE name = '".$_POST['name']."'");
$row = mysql_fetch_array($result);
if($row['name'] == $_POST['name'])
$errors[] = "- This category already exists!";
This works only when there is an exact match, for example, when the value in the database is "google" and I submit "google" into the form, it will return that it already exists. But if I input Google, it won't return that it already exists.
I have tried using "LOWER(naam)" in the query, but also that doesn't work. How would I be able to check if a value (case insensitive) already exists in the database, without having an extra field for example that inserts everything in lowercase.. :)
How would I check if something is already in the database, when trying to post something. I have the following database:
CREATE TABLE `doc_items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(75) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
I am using the following code to check if a value already exists:
$result = mysql_query("SELECT name FROM doc_items WHERE name = '".$_POST['name']."'");
$row = mysql_fetch_array($result);
if($row['name'] == $_POST['name'])
$errors[] = "- This category already exists!";
This works only when there is an exact match, for example, when the value in the database is "google" and I submit "google" into the form, it will return that it already exists. But if I input Google, it won't return that it already exists.
I have tried using "LOWER(naam)" in the query, but also that doesn't work. How would I be able to check if a value (case insensitive) already exists in the database, without having an extra field for example that inserts everything in lowercase.. :)