0

我有一个页面,您可以在其中将视频添加到播放列表。这是通过单击添加按钮来完成的。

然而问题是每次我去这个页面时,不管点击添加按钮,它都会将该视频添加到你的播放列表中,即使它已经存在。

您必须有一个帐户才能使用播放列表功能。添加按钮在您登录时可见,如果没有进入则看不到添加按钮。

这是我添加到数据库的代码:

if (isset($_SESSION['username'])){


                echo '<button type="submit" formmethod="post" formaction="video.php" onClick="Confirm(this.form)">ADD</button>';

                $userID = $_SESSION['username'];
                $ID = $watch;
                $artist = $new[0];
                $title = $new[1];
                $youtubeID = $code;
                include 'opendb.php';
                $sql = "insert into youtube_playlist (userid,youtubeID,artist,title) values ((select id from users where username = \"$userID\"),\"$youtubeID\",\"$artist\",\"$title\")";
                $result = mysql_query($sql,$conn) or die(mysql_error());

            }
            //if not logged in.
            else{
                echo "You are not logged in, you cant use the playlist feature.";
            }

因此,即使您登录并尝试观看视频,即使您不想,它也会将其添加到播放列表中。你如何确保这永远不会发生?

4

1 回答 1

2

你总是可以尝试这样的事情:

<html>
<head>
<title>My Website</title>
</head>
<body>
<?php
    if (isset($_POST['add'])) {
        $userID = $_SESSION['username'];
        $ID = $watch;
        $artist = $new[0];
        $title = $new[1];
        $youtubeID = $code;
        include 'opendb.php';
        $sql = "insert into youtube_playlist (userid,youtubeID,artist,title) values ((select id from users where username = \"$userID\"),\"$youtubeID\",\"$artist\",\"$title\")";
        $result = mysql_query($sql,$conn) or die(mysql_error());
    }

    if (isset($_SESSION['username'])){
        echo "<form action='' method='post'>
            <input name='add' type='submit' value='Add'/>
        </form>";
    } else {
        echo "You are not logged in, you cant use the playlist feature.";
    }
?>
</body>
</html>
于 2012-12-20T09:02:24.580 回答