How can I fix the code below?
He takes the spaces between the commas of the genres ie if I have these genres "action, adventure, romance" it puts so "action, adventure, romance" right? But if I do the reverse order (so "romance, adventure, action") or put more spaces between the commas in an altered or equal way (more or less this way: "action, adventure, romance" or "action, romance, adventure ") is giving error of inserting the same item in the table of MySQL genres.
How can I fix this?
<?php $generoMinusculo = strtolower(trim($_POST["genero"]));
if ($generoMinusculo) {
$generoMinusculo = str_replace(' ,',',',$generoMinusculo);
$generoMinusculo = str_replace(' , ',',',$generoMinusculo);
$generoMinusculo = str_replace(' , ',',',$generoMinusculo);
$generoMinusculo = str_replace(' , ',',',$generoMinusculo);
$generoMinusculo = str_replace(' , ',',',$generoMinusculo);
$generos = explode("," , $generoMinusculo);
foreach ($generos as $item) {
$Generos = mysql_query("SELECT * FROM 'generos' WHERE 'genero'='".$item."'");
$verificar = mysql_fetch_array($Generos);
$verificarGenero = $verificar["genero"];
$generoPostado = $item;
if ($generoPostado != $verificarGenero){
mysql_query("INSERT INTO 'generos' SET 'genero'='".$item."'");
}elseif ($generoPostado == $verificarGenero){ }
else { } } ?>