Well I'm here with a problem I have in my system categories in which I enter the products in the various categories that can choose through checkbox only I am now facing a problem and I want to delete a record eg: p>
I have a checkbox selected and it is stored in the database, so when I uncheck this box it goes out in the database. I tried to build the code here, but now you are not inserting or deleting the database. >
Php Code
<?php
if($_REQUEST['op']=="editar" && $_REQUEST['valida']=="ok"){
if($_REQUEST['op']=="editar"){
//$result_existe=mysql_query("select * from colecoes where activo=1");
//$row_existe=mysql_query($result_existe);
//$result_existe=mysql_query("select * from categorias_estabelecimentos where estabelecimento_id = '".$_REQUEST['id']."' and categoria_slug = '".$row_existe->slug."'");
//if(mysql_num_rows($result_existe)>0){
if (!isset($_POST['categoria'])){
foreach($_POST['categoria'] as $entry_categorias_delete){
$categorias_delete= $entry_categorias_delete;
$sql="DELETE FROM categorias_estabelecimentos WHERE estabelecimento_id = '".$_REQUEST['id']."' and categoria_slug='".$categorias_delete."'";
mysql_query($sql) or die (mysql_error() );
}
}
}else{
$checkBox = $_POST['categoria'];
$estabelecimento_id = $_REQUEST['id'];
foreach($checkBox as $entry_categorias){
$categorias= $entry_categorias;
$query="INSERT INTO categorias_estabelecimentos (estabelecimento_id, categoria_slug) VALUES ('".$estabelecimento_id."', '".$categorias."')";
mysql_query($query) or die (mysql_error() );
}
}
}
//}
?>