Jakesta42 Posted February 16, 2012 Share Posted February 16, 2012 Hey y'all, I'm trying to write a PHP script for a login function. There are three elements, two text fields (username and password) and a button which calls the script. Segment from index.php file: <form action = "login.php" method = "POST"> Admin Login: <br> Username: <input type = "text" name = "usernameField"/><br> <!-- Password field--> Password: <input type = "password" name = "passwordField"/><br> <!-- Username field --> <input type = "button" value = "Login" name = "submitButton"/> <!-- Login button --> </form> Segment from login.php file: <?php $connect = mysql_connect("localhost", "root", "root"); if(!$connect){//If user can't connect to database die('Could not connect: ' . mysql_error()); //Throw an error } mysql_select_db("colin_db", $connect); //Get given username and password from username field and password field $givenUsername = $_POST["usernameField"]; $givenPassword = $_POST["passwordField"]; $myQuery = "SELECT * FROM ADMINS WHERE USERNAME = '$givenUsername' AND PASSWORD = '$givenPassword'"; $queryResult = mysql_query($myQuery); $numRows = mysql_num_rows($queryResult); if($numRows == 1){ //If the details are correct... //Reload the page and login echo "<script type = 'text/javascript'> window.location.reload() </script>"; } elseif($numRows == 0){ //Else if the details are not found //Display error accordingly echo "Details not correct!"; } mysql_close($connect); ?> The problem is, when I click the login button, it doesn't do anything. What am I missing? (The information in the database is correct) Thanks, Jake 17583_.php Quote Link to comment https://forums.phpfreaks.com/topic/257110-really-basic-phpmysql-question-first-post/ Share on other sites More sharing options...
smerny Posted February 16, 2012 Share Posted February 16, 2012 change input type to 'submit' (instead of button) or add a javascript onclick event to submit the form if you really need it to be a button for whatever reason Quote Link to comment https://forums.phpfreaks.com/topic/257110-really-basic-phpmysql-question-first-post/#findComment-1318024 Share on other sites More sharing options...
PaulRyan Posted February 16, 2012 Share Posted February 16, 2012 Change: <input type = "button" value = "Login" name = "submitButton"/> To: <input type = "submit" value = "Login" name = "submitButton"/> Quote Link to comment https://forums.phpfreaks.com/topic/257110-really-basic-phpmysql-question-first-post/#findComment-1318026 Share on other sites More sharing options...
Jakesta42 Posted February 16, 2012 Author Share Posted February 16, 2012 change input type to 'submit' (instead of button) or add a javascript onclick event to submit the form if you really need it to be a button for whatever reason Okay, that issue is fixed; thanks so much. Still another issue stands. Is my SQL right? Because it says that the details are not correct (in my customized error message), but the information in the database matches my input. Is the way I'm determining if the login details are correct right? Quote Link to comment https://forums.phpfreaks.com/topic/257110-really-basic-phpmysql-question-first-post/#findComment-1318033 Share on other sites More sharing options...
smerny Posted February 16, 2012 Share Posted February 16, 2012 nvm, see you asked here http://www.phpfreaks.com/forums/index.php?topic=353890.msg1671486#msg1671486 Quote Link to comment https://forums.phpfreaks.com/topic/257110-really-basic-phpmysql-question-first-post/#findComment-1318089 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.