简体   繁体   English

PHP将用户添加到收藏夹系统?

[英]PHP Add User to Favorites System?

i'll try be as clear as possible. 我会尽量清楚。 I'm brand new to php and mysql so i'm sorry in advance because i'm probably a long way off accomplishing this, but i'm trying to allow users of mys site click a favorite button on another users profile and have this set the user to their favorites in mysql table. 我是php和mysql的新手,所以对不起,因为我可能要完成这个工作还很遥远,但是我正试图允许mys网站的用户单击另一个用户个人资料上的收藏夹按钮并拥有它将用户设置为他们在mysql表中的收藏夹。

So far i've designed a basic table like so: 到目前为止,我已经设计了一个基本表,如下所示:

    ID                 |             User_ID             |       Favorite_ID

ID Auto Incs by 1            Person Favouring User            User being favoured

I'm just trying to make it so that once the favorite button is pressed on the user's profile this a href's to favorite.php where this echo's the profile_id and the session id and stores the two in the table. 我只是想做到这一点,以便一旦在用户的个人资料上按下“收藏夹”按钮,便会将href转到“ favourite.php”,其中此回显即为profile_id和会话ID,并将两者存储在表中。

That should then allow me to set a query which pulls all the favorite id's WHERE the user_id is 'x'. 然后,这应该允许我设置一个查询,在其中user_id为'x'的情况下提取所有喜欢的ID。

Please can someone show me what i'd need to do. 请有人能告诉我我需要做什么。 thank you. 谢谢。

Here's my button link: 这是我的按钮链接:

<a href="favorite.php?to=<?php echo "$profile_id"; ?>">+ Favorite</a>

Here's my code i'm using: 这是我正在使用的代码:

<?php ob_start(); ?>
  <?php 

// CONNECT TO THE DATABASE
    require('includes/_config/connection.php');
// LOAD FUNCTIONS
    require('includes/functions.php');
// GET IP ADDRESS
    $ip_address = $_SERVER['REMOTE_ADDR'];

?>
  <?php require_once("includes/sessionframe.php"); 
?>

  <?php

    confirm_logged_in();

    if (isset ($_GET['to'])) {
    $user_to_id = $_GET['to'];  
}

?> 
  <?php 
            $sql = "INSERT INTO ptb_favorites (id, user_id, favorite_id) VALUES (NULL, '".$_SESSION['user_id']."', '".$user_to_id."');";
            mysql_query($sql, $connection);

            echo "<div class=\"infobox2\">User has been added to your favorites.</div>";
            header('Location: http://localhost/ptb1/profile.php');      
?>
<?php ob_end_flush() ?>

Change your button link 更改您的按钮链接

<a href="favorite.php?to=<?php echo "$profile_id"; ?>">+ Favorite</a>

To this 对此

<a href="favorite.php?to=<?php echo $profile_id; ?>">+ Favorite</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM