r1nk Posted August 29, 2013 Share Posted August 29, 2013 Hey, i got another question. Ok so far i have a table called users (id, name, username, pass, type) and here is my coding so far.. <html> <head> <title> Login Form </title> </head> <body> <form method='post' action='login.php'> <table width='400' border='5' align='center'> <tr> <td align='center' colspan='5'><h1>Login Form</h1></td> </tr> <tr> <td align='center'>Username:</td> <td><input type='text' name='username' /></td> </tr> <tr> <td align='center'>Password:</td> <td><input type='password' name='pass' /></td> </tr> <tr> <td align='center'> <select name="type" id="type"> <option value="0 selected="selected">Select user type</option> <option value="admin">Admin</option> <option value="student">Student</option> </select> </tr> <tr> <td colspan='5' align='center'><input type='submit' name='login' value='Log In' /></td> </tr> </table> </form> </body> </html> <?php mysql_connect("localhost","root",""); mysql_select_db("student_attendance"); if(isset($_POST['login'])){ $username = $_POST['username']; $password = $_POST['pass']; $type = $_POST['type']; $check_user = "select * from users where username='$username', pass='$password' AND type='$type'"; $run = mysql_query($check_user); if(mysql_num_rows($run)>0){ echo "<script>alert('You are logged in')</script>"; } else { echo "<script>alert('username,password or user type is incorrect!')</script>"; } } ?> And when i viewed it looks like this.. http://i272.photobucket.com/albums/jj178/r1nk_2008/prob_zpsd907ed84.png So my questions are :- -how to make the select box option to the right side, below the password form ? -how to fix the error so that when i enter correct username, pass and type it says "you are login" ? Quote Link to comment Share on other sites More sharing options...
fastsol Posted August 29, 2013 Share Posted August 29, 2013 Looks like most of the issue is with this block <tr> <td align='center'> <select name="type" id="type"> <option value="0 selected="selected">Select user type</option> <option value="admin">Admin</option> <option value="student">Student</option> </select> </tr> You're missing a clising </td> after the </select> and a closing " for the 1st option value. Quote Link to comment Share on other sites More sharing options...
r1nk Posted August 29, 2013 Author Share Posted August 29, 2013 thanx.. fixed that already.. now only 1 error left.. Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\wamp\www\student_attendance\login.php on line 57 Quote Link to comment Share on other sites More sharing options...
Solution fastsol Posted August 29, 2013 Solution Share Posted August 29, 2013 (edited) The comma in this snippet from the query needs to be replaced with AND username='$username', pass='$password' Add this line after the query run during production but remove it once the site is working echo mysql_error(); Edited August 29, 2013 by fastsol Quote Link to comment Share on other sites More sharing options...
r1nk Posted August 29, 2013 Author Share Posted August 29, 2013 Thanx.. i changed to "AND" and it works.. But i dun use the 2nd command.. Mine explaining me what its function for? And one more thing, how to make the select box option to the right side, below the password form ? Quote Link to comment Share on other sites More sharing options...
fastsol Posted August 29, 2013 Share Posted August 29, 2013 (edited) The mysql_error() will display the reason the query failed. To place the select box you need to add an empty td in the table <tr> <td></td> // This is the empty cell <td align='center'> <select name="type" id="type"> <option value="0 selected="selected">Select user type</option> <option value="admin">Admin</option> <option value="student">Student</option> </select></td> </tr> Edited August 29, 2013 by fastsol Quote Link to comment Share on other sites More sharing options...
r1nk Posted August 29, 2013 Author Share Posted August 29, 2013 Thanks.. Appreciate your help.. Quote Link to comment 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.