Creating login page with a student ID mysql and php

i have created a login page where a student is able to register using username, password and email. I have created a table which contains all the students ID. So when a students registers they have to enter a correct ID which has to match the table in order for them to register. I was wondering how can i do this. I am using php and mysql.

f(isset($_POST["submit"])){ `if(!empty($_POST['user']) && !empty($_POST['pass']) && !empty($_POST['email'])) {

$user=$_POST['user'];

$pass=$_POST['pass'];

$email=$_POST['email'];
  $con=mysql_connect('localhost','root','') or die(mysql_error());

mysql_select_db('user_registration') or die("cannot select DB");

query=mysql_query("SELECT * FROM login WHERE username='".$user."'");

$numrows=mysql_num_rows($query); if($numrows==0)

$sql="INSERT INTO login(username,password,email) VALUES('$user','$pass', '$email')";

$result=mysql_query($sql);

if($result){ echo "Account Successfully Created"; } else {

echo "Failure!";

else { echo "That username already exists! Please try again with another.";


else { echo "All fields are required!";

i have not included the student ID part as i am unsure


You would need to query the MySQL database and check that the user ID that the person has submitted is in the table. If it is in the table, then do whatever you want to do, or if not then tell the user that the user ID is incorrect.

It might help if you gave some more information about what you've actually already done...


like MattFiler said, you need to query the MYSQL database and check that the user ID and password a person has submitted is in the table or not. something like this;

PHP

require ('config.php');

if (isset($_POST['uname']) && isset($_POST['pass'])) {
    $user = $_POST['uname'];
    $pass = $_POST['pass'];
    $que = "SELECT * FROM login WHERE username = '$user' AND password = '$pass' ";
    $run = mysql_query($que);
    $row = mysql_fetch_array($run);
    $user_db = $row['username'];
    $pass_db = $row['password'];
    if ($user == $user_db && $pass == $pass_db) {
        echo "LOGGED IN!";

        // anything else you want to do here..

    }
    else {
        echo "INVALID USER ID OR PASSWORD<br />Please Sign Up if you are a new user.";
        die();
    }
}

HTML

<form action="" method="post">
    <p><label class="field">Username:</label></p>
    <input class="textbox-300" name="uname" pattern="[a-zA-Z0-9. ]+" required="" title="Please enter your Username" type="text">

    <p><label class="field">Password:</label></p>
    <input class="textbox-300" id="pass" name="pass" required="" type="password"> <input name="check" type="hidden">
    <input class="button" name="sub" type="submit" value="Login">
</form>

Note: this is just a demo, do it with mysqli/PDO and consider taking care of SQL Injection/XSS before you go live.

链接地址: http://www.djcxy.com/p/21876.html

上一篇: 如何使用PHP curl使用HTTP基本身份验证进行请求?

下一篇: 使用学生标识mysql和php创建登录页面