Eoin Posted May 14, 2012 Share Posted May 14, 2012 I am trying to create a login page where i am comparing a username and a password from two text boxes to a username and a password field from a database. I am having trouble getting the database variables to do the comparison with. /////HTML/////////////////////////////////////////////////////////////////////////// User Name: <input id="UserBox" type="text" name="uname" /><br /> Password: <input id="PassBox" type="password" name="pname" /><br /> <input id="theButton" type="button" class="roundedClass" value="Login" onClick="passCheck()" /> /////////////////////////////////////////////////////////////////////////////////////// <script type="text/javascript"> function passCheck() { var u = document.getElementById("UserBox"); var p = document.getElementById("PassBox"); if (u.value == $username && p.value == $password) { window.location.href ='mainPage.html'; } else alert("Invalid username or password.\nPlease try again ."); } </script> ///////////////////////////////////////////////////////// <?php // Include file to Connnect to online database include_once "mysql_connect.php"; // Collects data from table $data = mysql_query("SELECT * FROM login") or die(mysql_error()); while($info = mysql_fetch_array( $data )){ $username=$info['username']; $password=$info['password']; } ?> my question is how can i gain access to $username and $password so they can be used in the passCheck() function as they wont work as above?any help would be appreciated. Eoin. Link to comment https://forums.phpfreaks.com/topic/262517-login-help/ Share on other sites More sharing options...
Pikachu2000 Posted May 14, 2012 Share Posted May 14, 2012 When posting code, enclose it within the forum's . . . BBCode tags. Link to comment https://forums.phpfreaks.com/topic/262517-login-help/#findComment-1345341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.