System to identify that the user owns the topic PHP + Mysql

1

GOOD LATE. I'm doing a help forum on my site, and I came across a question. I tried to make sure that, when the owner of the topic was in doubt, he could close the topic himself. However, I have a certain message when trying to display the message for him to click. I've tried this:

    <?php
        $connect = mysql_connect('localhost','root','');
        $db = mysql_select_db('registro');
        $id = $_GET["id"];
    $sql = "SELECT 'Autor' FROM topicos WHERE 'ID' = '$id'";
    $limite = mysql_query("$sql");
    if ($sql = $login_cookie ) { // o $login_cookie é minha variavel que seleciona o nome de usuário, quando ele está ativo na conta
// então, tentei comparar o nome de usuário com o nome do autor do tópico
        echo "Fechar tópico";
    } else {
        echo "oi"; // mensagem só para certificar se funcionou
    }
    ?>

But I did not get results.

I do not want a complete code, I just want to know how I could do it, that is, in what way I could do it.

Well, through this edition, I've been saying that this system would help me in many other functions of my forum as well. I forgot to also tell you what's going on: By placing this code, the message is displayed regardless of who is logged in. I do not know if an image should help, but I think it better show what I do: link

    
asked by anonymous 03.02.2016 / 15:39

1 answer

1

No if are two = signs to compare. You did not get the result of your query , for that I used mysql_fetch_array() .

<?php
    $connect = mysql_connect('localhost','root','');
    $db = mysql_select_db('registro');
    $id = $_GET["id"];

    $sql = "SELECT Autor FROM topicos WHERE ID = $id";
    $limite = mysql_query($sql);
    $res = mysql_fetch_array($limite);

    if ($res['Autor'] == $login_cookie ) { 
        echo "Fechar tópico";
    } else {
        echo "oi";
    }
?>

Verification on same SELECT :

SELECT Autor FROM topicos WHERE ID = $id AND Autor = '$login_cookie' ;

You are checking above if the specific topic was created by the logged-in User Author.

Then you do another check asking how many rows have been returned. In this case 1 or 0 should be returned.

Then:

$limite = mysql_query($sql);
$numlinha = mysql_num_rows($limite);

if($limite == 1)
    echo "Criou";
else
    echo "Não criou";
    
03.02.2016 / 15:48