mardi 30 juin 2015

Use PHP if statement on query result

I'm having a problem getting useful information from my query results. I want to query the database for a postID, and if it is the same with the current post, I want to then leave a message, if not the same, I want to show an input. This is so that the user cannot enter more than one posts, so once the user has entered one posts, the input box vanishes and the mentioned messaged appears "Already Entered". Here's my code:

$wpdbtest_maindb = new mysqli('localhost', 'xxx', 'yyy', 'i1593382_wp1');

                    $result = mysqli_query($wpdbtest_maindb,"SELECT user_id, post_id
                                            FROM giveaways
                        WHERE user_id= $user_ID");



                    if (mysqli_num_rows($result) > 0) {
                    while($row = mysqli_fetch_assoc($result)){
                        $post_id = $row[post_id];
} 
                        if ($id == $post_id)
                        {
                            echo "Already Entered";
                        }else{?>
<form action="../../giveaways.php" method="post">                                   
                    <input type="hidden" name="postid" value="<?=$id?>" />
                    <input type="hidden" name="userid" value="<?=$user_ID?>" />
                    <p align="right"><input type="submit" value="<?=$user_ID?>-<?=$id?> Enter" class="submit" />        </p>
                    </form> 
<?php
}
 } 
}


?>                  

Aucun commentaire:

Enregistrer un commentaire