Well the below code is an incomplete rewrite of a login script I wrote. It's still very much under construction so please no criticism. Anyway, it calls itself through Ajax to perform the login and such and is then supposed to call itself through Ajax again with a message stating the login was successful. The only problem is that where the Ajax function is called the second time, nothing is happening. I placed a simple echo to ensure that the block is being stepped into and it in fact is but the Javascript function is simply not executing the second time.
<?php
//If not logged in.
include 'mysql_connect.php';
$form_data = explode(',',$_POST['var1']);
Session_start();
if (!isset($_SESSION['username']))
{
//Perform login.
if (isset($form_data[2]))
{
$username = strip_tags($form_data[0]);
$password = md5(strip_tags($form_data[1]));
//Query user table for user information.
$userinfo = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
list($id, $username, $password, $email) = mysql_fetch_row($userinfo);
$_SESSION['username'] = $username;
//Query character table for char info.
$charinfo = mysql_query("SELECT name,class FROM characters WHERE id='$id'");
list($charname, $class) = mysql_fetch_row($charinfo);
$_SESSION['char'] = $charname;
$_SESSION['class'] = $class;
$_SESSION['id'] = $id;
echo "poop<script language='javascript'>alert('poop')</script>"; <---javascript code right here isn't executing
/*echo "<script language='javascript' TYPE='text/javascript'>
alert('Poop');
send(\'You are now logged in.\',\''.$path.'/display_files/statistics.php\',\'stats\');
</script>";*/
}
//Display login form.
else
{
echo'<center><br>
Username: <input type="text" onchange="varArr.push(this.value)" size="15" maxlength="15"><br>
Password: <input type="password" onchange="varArr.push(this.value)" size="10" maxlength="10"><br>
<input type="submit" value="Login" onclick="varArr.push(this.value);send(varArr,\'display_files/statistics.php\',\'stats\')">
<br>
<a href="index.php?act=register">Register</a></center>';
}
}
//If logged in.
else
{
//Logout.
if (isset($_POST['logout']))
{
session_destroy();
}
//Show statistics.
else
{
$class = classname($_SESSION['class']);
$charname = $_SESSION['char'];
echo"<center>$charname</center>
<center>$class</center><br>
<center><form action='$_SERVER[PHP_SELF]' method='POST'>
<input type='hidden' name='header' value='index'>
<input type='submit' name='logout' value='Logout'>
</form></center>";
}
}
?>
Thanks in advance for any help. I have a suspicion that the problem is that Ajax or any Javascript may not be executed within an Ajax stream, but this is only a thought. Any help or suggestions would be greatly appreciated. Also refrain from unrelated statements such as "you are not validating your login" as I said this script is under construction still and I am simply trying to debug this one error before I fix the rest.