I have the following PHP code which is for an application voting system. Its a Q & A application, and the user can vote for questions and answers that are published.
In my php code, I first check if the user voted for a specific question. This will exist in the QVOTES table, with the email address and the ID of the question that was voted on.
When doing this check, I'm not sure how to see if $ result is an empty set to send a user vote if they have not voted for the question yet.
How can I make this work? All help is appreciated.
<?php $con=mysqli_connect("127.2.1.1","S837","887","D887"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $qid = $_POST['qid']; $email = $_POST['email']; $result = mysqli_query($con, "SELECT * FROM QVOTES WHERE QID = $qid AND EMAIL = '$email'"); if (!mysqli_num_rows($result) ){ if ($result = mysqli_query($con, "INSERT INTO QVOTES (QID, EMAIL) VALUES ($qid, '$email')")) { mysqli_query($con, "Update QUESTIONS SET VOTES = VOTES +1 WHERE QID = $qid"); echo "Update successful"; } else{ echo "Update unsuccessful"; } } else{ echo "null"; } mysqli_close($con);
source share