Duplicate Error Messages [RESOLVED]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Duplicate Error Messages [RESOLVED]

Post 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>
Last edited by Epiales on Sun Sep 28, 2014 1:23 am, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Duplicate Error Messages

Post 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 :)
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”