Dethman Posted January 5, 2010 Share Posted January 5, 2010 Ok here is all of my code first off. Javascript: <script> function login() { var user = document.getElementById("user"); var pass = document.getElementById("pass"); // Set up request varible try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { alert("Error: Could not load page.");} //Show page is loading document.getElementById("login_error").innerHTML = 'Logging In<BR /><img src="img/ajax-loader2.gif">'; //scroll to top scroll(0,0); //send data xmlhttp.onreadystatechange = function(){ //Check page is completed and there were no problems. if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { //Write data returned to page var resp = xmlhttp.responseText; if(resp == "loggedin"){ window.location = "base.php"; }else{ document.getElementById("login_error").innerHTML = xmlhttp.responseText; } } } xmlhttp.open("GET", "login.php?user=" + user + "&pass=" + pass + ""); xmlhttp.send(null); //Stop any link loading normaly return false; } </script> Login Form: <TABLE class=small style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px" width=130 align=center> <TBODY> <TR> <TD align=middle style="color:red;"><div id="login_error"></div></TD> </TR> <TR> <TD align=middle><FONT color=black><img src="img/user.gif"></FONT></TD></TR> <TR> <TD align=middle><INPUT class=login_input name="user" id="user" style="background:#fff;color:#000;"></TD></TR> <TR> <TD align=middle><FONT color=black><img src="img/pass.gif"></FONT></TD></TR> <TR> <TD align=middle><INPUT class=login_input style="background:#fff;color:#000;" type=password name="pass" id="pass"></TD></TR> <TR> <TD style="PADDING-TOP: 5px" align=middle><INPUT class=login_input style="WIDTH: 50px; background:#fff;color:#000;cursor:pointer;" type="submit" value=Login onclick="javascript:login()"></TD></TR> </TBODY></TABLE> PHP File login.php: <?php include "vsys.php"; // Database Connection Script /* Login.php */ function cleanuserinput($dirty){ if (get_magic_quotes_gpc()) { $clean = mysql_real_escape_string(stripslashes($dirty)); }else{ $clean = mysql_real_escape_string($dirty); } return $clean; } if(isset($_GET['user'])){ if(isset($_GET['pass'])){ $user = cleanuserinput($_GET['user']); $pass = cleanuserinput($_GET['pass']); $res = mysql_query("SELECT `ID` FROM `UserDetails` WHERE `userName` = '$user' AND `password` = '$pass'") or die("Error:<BR />".mysql_error()); $count = mysql_num_rows($res); $row = mysql_fetch_array($res); if($row['ID'] == ""){ die("Invalid Username or Password!"); }else{ $_SESSION["isLogined"] = $row['ID']; die ("loggedin"); } } } ?> Ok If I type in the correct user and pass thru the form it still dies Invalid Username and Pass If I do it like so "http://localhost/login.php?user=Brian&pass=mypass it actually sets the session and dies loggedin. For some reason the ajax is not sending the correct information to the php file. If anyone out there can help that would be good! also to the mods on the forums, I am not sure if this should be posted in javascript help if so please move this to wherever need. Thank you, Brian Link to comment https://forums.phpfreaks.com/topic/187229-ajax-and-php-login-not-forwarding/ Share on other sites More sharing options...
rajivgonsalves Posted January 5, 2010 Share Posted January 5, 2010 this var user = document.getElementById("user"); var pass = document.getElementById("pass"); should be var user = document.getElementById("user").value; var pass = document.getElementById("pass").value; Link to comment https://forums.phpfreaks.com/topic/187229-ajax-and-php-login-not-forwarding/#findComment-988756 Share on other sites More sharing options...
Dethman Posted January 5, 2010 Author Share Posted January 5, 2010 Thank you very much it is now working Link to comment https://forums.phpfreaks.com/topic/187229-ajax-and-php-login-not-forwarding/#findComment-988757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.