vendredi 27 février 2015

Use an IF STATEMENT with INSERT IGNORE

I have a voting system, which users can use to vote on posts. Thing is, they can't vote twice on the same post. Which is good. I did that like this:



$query = "INSERT IGNORE INTO vote_id (vote, postid, userid)
VALUES ('1', '{$postid}', '{$userid}')";
$result = mysqli_query($db, $query);
header('Location: index.php');


(The $db is my variable that connects to the database).

They can still click on the vote, even if it doesn't insert into the table.

My problem is:

When it is "IGNORE" they shouldn't be able to click.



My question is:

How do I separate the INSERT and IGNORE, so I can use the IGNORE in an IF statement? Or in any other way, that can change the layout of the page.



Thanks in advance! Really struggling with this one.


Aucun commentaire:

Enregistrer un commentaire