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.

Duplicate Error Messages [RESOLVED]

Postby Epiales » Sat Sep 27, 2014 5:26 pm

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 Sat Sep 27, 2014 8:23 pm, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
 
Posts: 1119
Joined: Wed Aug 14, 2013 8:38 pm
Has thanked: 62 times
Been thanked: 6 times

Re: Duplicate Error Messages

Postby Epiales » Sat Sep 27, 2014 8:23 pm

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
User avatar
Epiales
 
Posts: 1119
Joined: Wed Aug 14, 2013 8:38 pm
Has thanked: 62 times
Been thanked: 6 times


Return to Beginner Help and Support

Who is online

Users browsing this forum: No registered users and 0 guests

cron

x