Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
$dbhost = "localhost";
$dbname = "checkboxlistview";
$dbuser = "root";
$dbpass = "";
$con=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname) or die('Database not connected');
if(isset($_POST["email"]) && isset($_POST["favouriteCategories"]) )
{
$email=$_POST["email"];
$categoryid=$_POST["favouriteCategories"];
$cat_ids=(explode(",",$categoryid));
$count= count($cat_ids);
$query_delete="DELETE FROM favouritecategories WHERE email ='$email'";
mysqli_query($con, $query_delete);
for ($i=0; $i < $count ; $i++)
{
$catid = $cat_ids[$i];
$query_insert="INSERT INTO `favouritecategories`(`email`, `categoryId`) VALUES ('$email',$catid)";
mysqli_query($con, $query_insert);
}
echo 'Favourite Categories Updated';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.