Page 1 of 1

Duplicate Error Messages [RESOLVED]

PostPosted: Sat Sep 27, 2014 5:26 pm
by Epiales
Hey all, I'm using Javascript to display error messages, but it's duplicating the error message for some items but not others. I don't see anywhere it would do that. Hope you can find the error.

Javascript code to display the message:

Code: Select all
<script type="text/javascript">

    window.onload = function()
    {
        timedHide(document.getElementById('errormess'), 500);
    }

    function timedHide(element, seconds)
    {
        if (element) {
            setTimeout(function() {
                element.style.display = 'none';
            }, seconds*1000);
        }
    }
</script>


Then I just write the message like this:

Code: Select all
echo "<span id='errormess'><big><b><center><font color='red'>You do not have enough money to purchase this item</font></center></b></big></span>";


It duplicates the message for some reason. I don't see any reason why.

Here is the script in action

Code: Select all
<script type="text/javascript">

    window.onload = function()
    {
        timedHide(document.getElementById('errormess'), 500);
    }

    function timedHide(element, seconds)
    {
        if (element) {
            setTimeout(function() {
                element.style.display = 'none';
            }, seconds*1000);
        }
    }
</script>

<?php

if(isset($_GET['randid'])) {

$id = $_SESSION['userid'];
$randid=$_GET['randid'];

$sql = "SELECT * FROM usershop WHERE randid='$randid'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {


if ($user_money < $row['price'])
{
echo "<span id='errormess'><big><b><center><font color='red'>You do not have enough money to purchase this item</font></center></b></big></span>";
}
?>

<script>
setTimeout(function () {
   window.location.href= 'mafiawarskingdom.php?usershop=1';

},2000);
</script>

Re: Duplicate Error Messages

PostPosted: Sat Sep 27, 2014 8:23 pm
by Epiales
Amaingly how it takes hours to skim through code and stuff to only find out the database had two identical random numbers, so it echo'd the error message two times :lol: :lol: :lol:

Thanks anyway :)