php 收藏功能
Posted 安果移不动
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 收藏功能相关的知识,希望对你有一定的参考价值。
<?php
/**
* Created by PhpStorm.
* User: liuan
* Date: 2018-11-23 0023
* Time: 16:25
*/
header('content-type:text/html;charset=utf-8');
include_once './lib/fun.php';
if (!$login = checkLogin())
msg(2, '请登录',"login.php","collection.php");
$userId = (int)$_SESSION['user']['id'];
$goodsId = (int)$_GET['id'];
$type = (int)$_GET['type'];
// 数据库操作
$con = mysqlinit();
if ($type == 1)
//点击收藏
$sql = "INSERT INTO `la_collection`( `user_id`, `good_id`) VALUES ($userId,$goodsId)";
//商品本身表格的收藏+1
$sql2 = "UPDATE `la_goods` set `collection_count`=`collection_count`+1 where `id`=$goodsId and (`status`=1 or `status`=3)";
elseif ($type == 2)
$sql = "DELETE FROM `la_collection` WHERE `user_id`=$userId and `good_id`=$goodsId";
//商品本身表格的收藏-1
$sql2 = "UPDATE `la_goods` set `collection_count`=`collection_count`-1 where `id`=$goodsId and (`status`=1 or `status`=3) and `collection_count` > 0";
if (!$res = mysqli_query($con, $sql))
echo "查询语句失败", mysqli_error($con), $sql;
exit;
if (!$res2 = mysqli_query($con, $sql2))
echo "查询语句失败", mysqli_error($con), $sql2;
exit;
if (mysqli_affected_rows($con) > 0)
echo "<script>;history.back();</script>";
else
echo "收藏或者取消收藏失败";
以上是关于php 收藏功能的主要内容,如果未能解决你的问题,请参考以下文章