English 中文(简体)
php/ Mysql 的注册系统: 找不到用户
原标题:register system with php/mysql: can t find user

i 是在 php/ mysql 中是新来的, 抱歉如果我的问题很傻的话。 我正在尝试用 php 和 Mysql 建立一个注册/ login/ logout 系统。 我的技巧不好, 我不是一个程序员, 所以我试图更改我在网络上找到的脚本。 它包含文件, 索引. php, 激活 php. login. php, 登录. php, 注册. php 。

当我尝试给定的示例时,它效果很好, 但i 更改了代码相当大一点, 因为我希望用户在注册簿中添加更多的数值, 如名、 姓等, 而不仅仅是用户名、 密码和电子邮件。 因此我修改了代码, 在 Mysql 数据库中添加了更多的列。 现在它不起作用了, 它表示当我尝试激活时找不到用户, 我也可以登录 。

< 加强> index.php: 是一个非常简单的文件, 它有 html 格式, 询问未知用户是否想要登录或注册并同时启动会话

<强度> logout.php: 简单解密会话

<强>login.php:

 <?php session_start(); ?>
<html>
<body>
    <?php
    if(isset($_POST["user"])){
        $con = mysql_connect("localhost","root","password");
        if (!$con)
          {
          die( Could not connect:   . mysql_error());
          }

        mysql_select_db("myapp", $con);

        $sql = "SELECT * FROM `users` WHERE `user` LIKE  ". mysql_real_escape_string($_POST["user"])
        ."  AND ".
            "`pass` LIKE MD5( ". mysql_real_escape_string($_POST["pass"])
        ." ) AND ".
            "`active` =  DONE ";

        $result = mysql_query($sql);

        $found = 0;
        while ($row = mysql_fetch_array($result)) {
            if ($row[1]==$_POST["user"]) {
                $found = 1;
            }
        }

        if ($found) {
        $_SESSION["USER"] = $_POST["user"];
        ?>Thank you for logging in<?
        }
        else {
        ?>User/Pass is wrong!<?
        }

        mysql_close($con);
    }
    else {
    ?>

        Please log-in:<br/>
        <form action="login.php" method="POST">
            User: <input type="text" name="user"><br />
            Pass: <input type="password" name="pass"><br />
            <input type="submit" />
        </form>

    <?php
    }
    ?>

<强度 > 登记员.php:

<?php session_start(); ?>
<html>
<body>
<?php
    if(isset($_POST["user"])){
        $con = mysql_connect("localhost","root","password");
        if (!$con)
          {
          die( Could not connect:   . mysql_error());
          }

        mysql_select_db("myapp", $con);

        $random = rand();

        $sql = "INSERT INTO `myapp`.`users` (`id`, `user`, `pass`, `active`, `firstname`, `lastname`, `mail`) ".
        " VALUES (NULL,  ". mysql_real_escape_string($_POST["user"])
        ." , MD5( ".mysql_real_escape_string($_POST["pass"])
        ." ),  ".mysql_real_escape_string($random)
        ." ),  ".mysql_real_escape_string($_POST["firstname"])
        ." ),  ".mysql_real_escape_string($_POST["lastname"])
        ." ) ".mysql_real_escape_string($_POST["mail"])
        ." );";

        mysql_query($sql);

        mysql_close($con);

        $message = "Please put this url http://localhost/mypage/activate.php?active=" . $random . " in your browser to activate your account.";
        @mail($_POST["mail"],  Thank you for registering , $message);

        ?>Thank you <?php echo $_POST["user"]; ?> we send you a confirmation e-mail in <?php echo $_POST["mail"]; ?><?php

        echo $message;
    }
    else {
        ?>
        Please register:<br/>
        <form action="register.php" method="POST">
            User: <input type="text" name="user"><br />
            Pass: <input type="password" name="pass"><br />
            firstname:<input type="text" name="firstname"><br />
            lastname:<input type="text" name="lastname"><br />
            mail: <input type="text" name="mail"><br />

            <input type="submit" />
        </form>

        <?php
    }
?>

activate.php: 。 php:

<?php session_start(); ?>
<html>
<body>
        <?php
    if(isset($_GET["active"])){
        $con = mysql_connect("localhost","root","password");
        if (!$con)
          {
          die( Could not connect:   . mysql_error());
          }

        mysql_select_db("myapp", $con);

        $sql = "SELECT * FROM `users` WHERE `active` LIKE  ".      
mysql_real_escape_string($_GET["active"])." ";

        $result = mysql_query($sql);

        $found = 0;
        while ($row = mysql_fetch_array($result)) {
            $found = 1;
        }

        if ($found) {

        $sql = "UPDATE `users` SET `active` = DONE ";

        $result = mysql_query($sql);

        ?>Thank you for activating<?
        }
        else {
        ?>Can t find user!<?
        }

        mysql_close($con);
    }
    else {
    ?>Invalid activation<?php
    }
    ?>
</body>
</html>

任何帮助都会受到欢迎,

最佳回答

In register.php, you have an error in the SQL syntax, you have too many closed parentheses.
Replace this part like this:

$sql = "INSERT INTO `myapp`.`users` (`id`, `user`, `pass`, `active`, `firstname`, `lastname`, `mail`) VALUES 
   (NULL,". 
   " ". mysql_real_escape_string($_POST["user"])." ,".
   "MD5( ".mysql_real_escape_string($_POST["pass"])." ),".
   " ".mysql_real_escape_string($random)." ,".
   " ".mysql_real_escape_string($_POST["firstname"])." ,".
   " ".mysql_real_escape_string($_POST["lastname"])." ,".
   " ".mysql_real_escape_string($_POST["mail"])." );";
问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签