Variable doesn't get defined/updated after function processes?
<p>I have coded some alerting system.</p>

<p>But let's not look at the system itself, Let's look at how will the system know that the system really did sent the alert/error to the browsing user.</p>

<p>I have made something so when you randomly go to ?alert=name, without doing any error, it will say 'No errors'.
But if the system makes you go to ?alert=name, it will echo the error.</p>

<p>How I handle posts</p>

<pre><code>function postComment() {
    if (!empty($_POST['name']) || !empty($_POST['comment'])) {
        $comment = mysql_real_escape_string(htmlentities($_POST['comment']));
        $guest = mysql_real_escape_string(htmlentities($_POST['name']));
    }
    $guestId = 1;
    if (empty($guest)) {
        $alert = 1;
        return header('location: index.php?alert=name');
    }
    if (empty($comment)) {
        $alert = 2;
        return header('location: index.php?alert=comment');
    }
    if (!isset($_COOKIE['alreadyPosted'])) {
        mysql_query("INSERT INTO `comments` (`comment_guest`, `guest_id`, `comment`, `comment_date`, `comment_time`) VALUES ('$guest', '$guestId', '$comment', CURDATE(), CURTIME())") or die(mysql_error());
        header('Location: index.php?action=sucess');
        setcookie(alreadyPosted, $cookieId+1, time() + 60);
        } else {
            $alert = 3;
            header('location: index.php?alert=delay');
        }
}
</code></pre>

<p>As you see, to check if user really getting that error, I will set $alert to whatever error number it is.</p>

<p>And to check if hes getting the error I will use this:</p>

<pre><code>if (isset($_GET['alert']) == 'name') {
    if ($alert == 1) {
        echo 'hai';
    } else {
        echo 'No errors';
    }
}
</code></pre>

<p>You will probably wonder why I am doing it this way.., well because I use 1 function for post, and my  post function goes under the form, and i want the alerts to display up to the form.</p>

<p>Problem:</p>

<p>The variable either doesn't get set to the number that it is supposed to when running the function,
or.. something is blocking it from it.. I don't know..</p>

<p>My guess: Because the check for errors is located up to the postComment function before the variables even get set?</p>

<pre><code>&lt;?php
    if (isset($_GET['alert']) == 'name') {
        if ($alert == 1) {
            echo 'hai';
        } else {
            echo 'No errors';
        }
    }
    ?&gt;

&lt;form action="index.php" method="POST"&gt;
&lt;input type="text" name="name" placeholder="Your name here" class="field"&gt;
&lt;textarea class="textarea" name="comment" placeholder="Your comment here..."&gt;&lt;/textarea&gt;
&lt;input type="submit" name="send" class="blue_button" value="Post Comment"&gt;
&lt;/form&gt;&lt;a href="#"&gt;&lt;input type="submit" name="" id="margin" class="blue_button" value="See all messages"&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;?php
//Show the comments
    showComments();

    if (isset($_POST['send'])) {
        postComment();
    }

    if (isset($_GET['delete']) == "comment"){
        deleteComment();
    }

    echo '&lt;br /&gt;';

?&gt;
</code></pre>

<p>If it is, what is the solution?
Thanks!</p>

<p>Please don't start with the story about mysql_ function, I understood &amp; I will use PDO instead, but I am using mysql_ at the moment for testing purposes </p>
