vendredi 29 janvier 2021

Adding Record to a Database Using a Button

I am making a website that stores videos. I would like to be able to have a button that adds a video to a table called Favourites which has the videoID, videoRef(youtube embed code) and the userID of the user that has clicked the button. I have tried a few things but for the most part I didn't know what I was doing. Code:

$user = $_SESSION["user"];

$GetUserID = mysqli_query($link, "SELECT userID FROM users WHERE username = '$user'");

$query=mysqli_query($link, "SELECT * FROM videos WHERE videoID = '$id'");

while ($data = mysqli_fetch_array($query) ){
    
    $GetVideoID = $data['videoID'];
    $GetVideoRef = $data['videoRef'];
    
}

if(isset($_POST['submit'])){
    
    $insert = mysqli_query($link,"INSERT INTO favourites (userID, videoID, videoRef) VALUES ('$GetUserID', '$GetVideoID', '$GetVideoRef')");

}

In my eyes this is the right logic but I'm quite new to websites. Any tips or solutions at all would make a big difference.




Aucun commentaire:

Enregistrer un commentaire