单击登录时没有任何反应

时间:2013-09-22 12:13:48

标签: php html mysql ajax

我试图创建一个登录页面,但它似乎不起作用。当我单击“登录/注册”时,会显示一个弹出窗口。我输入详细信息并单击登录。什么都没发生。我尝试注册,但仍然没有任何反应。

我的主页

<HTML>
<HEAD>
<TITLE>Experiment on Social Network</TITLE>
<script src = "jscript.js"></script>
<link rel = "stylesheet" type = "text/css" href = "style.css" />
<script type = "text/javascript">
window.onload = function()
{
    document.getElementById("LoginBtn").onClick = sendRequest("login.php");
    document.getElementById("SignBtn").onClick = sendRequest("Signup.php");
};
</script>
</HEAD>
<BODY bgcolor = "black" text = "white" alink = "blue" vlink = "cyan">
<a href = "..//index.html">Home</a>
<div id = "responseOutput">
<a id = "logSign_pop" href = "#logSign">Login or Signup</a>
<a href = "#x" class="overlay" id="logSign"></a>
    <div class = "popup">
            <h1>Welcome Guest!</h1>
        <form action = "#">
        <h3>Login Here</h3>
        <label for = "user">Username</label>
        <br />
        <input type = "text" id = "uname" value = "" />
        <br />
        <label for = "password">Password</label>
        <br />
        <input type = "password" id = "pass" value = "" />
        <br />
        <input type="button" id = "LoginBtn" value="Log In" />
        <a class="close" href="#close"></a> 
    </form>
    <form action = "#">
        <h3>Sign Up</h3>
            <label for="firstName">First Name</label>
            <br/>
            <input type="text" id="firstName" value="" />
            <br />
            <label for="lastName">Last Name</label>
            <br/>
            <input type="text" id="lastName" value="" />
            <br />
            <label for="useName">UserName</label>
            <br/>
            <input type="text" id="useName" value="" />
            <br />
            <label for="email">Email</label>
            <br/>
            <input type="text" id="email" value="" />
            <br />
            <label for="pass">Password</label>
            <br/>
            <input type="password" id="pwd" value="" />
            <br />
        <input type="button" id = "SignBtn" value="Sign Up" />
        <a class="close" href="#close"></a>
    </form>
</div>
 </div>
<br/>
<center>
<h1>Welcome to MaxZeroEdge Network</h1>
</center>
</BODY>
</HTML>

的login.php

<?php
$logID = $_POST["uname"];
$pass = $_POST["pass"];
$login = 0;
$con = mysql_connect("localhost","admin","admin");
    if (!$con)
        {
            die('Could not connect to database: '. mysql_error());
        }

    $db = mysql_select_db("logDat", $con);
    if(!$db)
    {
        create_db();
    }

    $tb = "SELECT * from logDat";
    $av = @mysql_query($tb);
    if(!$av)
    {
        echo "Error creating database: " . mysql_error();
    }
    else
    {
        checkLogin();
    }

function checkLogin()
    {
        //Checks if a particular value exists
        $result = mysql_query("SELECT * FROM logDat");
        //$passResult = mysql_query("SELECT password FROM logDat");
        $check = $logID;
        while($login == 0 && $row = mysql_fetch_array($result))
        {
            if($row["Username"] == $logID)
            {
                if($row["password"] == $logPass)
                {
                    /*$login = 1;
                    $expire = 86400*7;
                    setcookie("user",$logID,$expire);*/
                    $_SESSION["userid1"] = $logID;
                    print "<message>Welcome $logID</message>";
                    //header("Location: Social Network.php"); // redirects
                }
                else echo "Incorrect Password.";
            }
            else echo "User doesn't exist.";
        }
    }

    //Runs for the first time only. Creates the database    

    function create_db()
    {
        if (mysql_query("CREATE DATABASE logDat",$con))
        {
            echo "Database created";
        }
        else
        {
            echo "Error creating database: " . mysql_error();
        }
    }   

//Runs for the first time only. Creates the table.

    function create_table()
    {
        //Password varchar(20),
        $user = "CREATE TABLE logDat
        (
            personID int NOT NULL AUTO_INCREMENT,
            PRIMARYKEY(personID),
            Username varchar(20),
            FirstName varchar(50),
            LastName varchar(50),
            Email varchar(100),
            password varchar(20);
        )";
        mysql_query("INSERT INTO logDat(PRIMARYKEY, Username, FirstName, LastName, Email, password) VALUES(0, 'zero', 'Palash', 'Max', 'maxzeroedge@gmail.com', 'hellfire') ");
    }

mysql_close($con);  
?>

1 个答案:

答案 0 :(得分:1)

删除javascript window.onload功能

使用输入类型submit作为按钮,并将目标页面添加到action

如:

<form action = "login.php" method='post'>

<input type="submit" id = "LoginBtn" value="Log In" />

而不是

<form action = "#">

<input type="button" id = "LoginBtn" value="Log In" />

Sugn Up部分相同