This now has me confused. So you are getting into the if branch or no?
Check your source HTML code. If it shows the script tags as expected, than this is not a PHP issue.
So when count is 1, you should see this in the HTML source:
Code:
<script type='text/javascript'>
window.alert('Welcome: ' . yourusername . ' you are successfully logged in.')
window.location.href='securepage.php';
</script>
And this when count is not 1:
Code:
<script type='text/javascript'>
if (window.confirm('Username or Password INCORRECT! Do you wish to REGISTER?')
window.location.href='register.php'; // If OK pressed
else
window.location.href='index.php'; // If Cancel pressed
</script>
Do you see both of these properly when you control the $count? If that is in the source, than PHP has done its job. It's up to the browser to do something with the JS code.
As for the username not showing up in the alert, that's because your JS code is broken. You have used single quotations and then used single within it. Remove those single quotations within and wrap the session access into {} to force complex evaluation. Or break the double quotes, whichever you like.