samedi 7 mars 2020

Like random person PHP from rand

Hey guys i'm trying to make a match system. Plan is simple get random person from database display on site save id in variable and by clicking "like" button insert to database id (user) and likes (user that i liked). I'm not getting any errors but i just cant get variable of user that i liked, how should i do it?

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">

  <title>The HTML5 Herald</title>
  <meta name="description" content="The HTML5 Herald">
  <meta name="author" content="SitePoint">

  <link rel="stylesheet" href="cs.css">

</head>

<body>

</body>
</html>
<?php


include_once 'zdjecie.php';
include_once 'dbh.php'; 
include_once 'session.php';
$id= $_SESSION['userId'];




      if (isset($_POST['losuj'])){
        // random person
        $sql= "SELECT * FROM  users  ORDER BY RAND () LIMIT 1 ; ";
        $result = mysqli_query($conn, $sql);
        $resultCheck = mysqli_num_rows($result);        
        if ($resultCheck> 0){
        while ($row = mysqli_fetch_assoc($result)){        
        //saving to variable
        $nick = $row['uidUsers'];
        $ide= $row['idUsers'];
        //display
        echo"<div class = 'column'";
        echo "<h1 align= 'center'>".$nick."</h1>"; 
        echo "<br>";
        echo "<br>";
        echo "<img class= 'photo' src='images/".$row['zdjecia']."' width='300' height='300' />";
        echo "</div>";
        echo "<form action='' method='post'>
        <button name='like' value='like'>like</button>
        </form>"; 
        break;



        }
    }
}
echo $row['idUsers'];
if (isset($_POST['like'])){
    //adding to database
    $sql = "INSERT INTO likes (id, likes)
    VALUES ('$id', '$ide')";
    echo $ide;


    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();




  }      



?>
<form action ="logout.php" method="post"> 
<button type = "subbmit" name ="logout-subbmit"> logout </button> 
</form>
<form action="losowanieproba.php" method="post"> 
<div class = "roll">
<button  name= "losuj" value= "losuj"> losuj </button>
</div>
</form>



Aucun commentaire:

Enregistrer un commentaire