Home>

I'm currently working on creating an app.
I want to log in using the data saved in sql, but I cannot log in to the target page.

As for the flow of the application,
① new_log.php → Enter the information of the new registrant
➁ find.php → Check new registrant information and save in mysql
③ Transition to ok.php and enter login.php from the link tag in ok.php.
④ login.php → Call the information of the new registrant, log in, and move to check.php
It will be.

I have confirmed that the registrant information is saved in mysql.

What I think is the reason why I can't log in
・ There is a problem with how to call the registered vehicle information.
-The stored variables are described in the wrong process.
It is two points.

Please tell me the cause and solution of not being able to log in. Thank you.

=== new_log.php ===<? php
// Bring information in session
session_start ();
require ('../conect.php');
// Check if name and password are empty
if ($_ POST) {
    if ($_ POST ['name'] ==='') {
        $error ['name'] ='blank';
    }
    if (strlen ($_ POST ['password'])<4) {
        $error ['password'] ='length';
    }
    if ($_ POST ['password'] ==='') {
        $error ['password'] ='blank';
    }
    // Check if the password is covered
    if (empty ($error)) {
        $member = $db->prepare ('SELECT COUNT (*) AS cnt FROM member WHERE password =?');
        $member->execute (array ($_ POST ['password']));
        $record = $member->fetch ();
        if ($record ['cnt']>0) {
            $error ['password'] ='duplicate';
        }
    }
    // If the error is empty, transition to find.php
    if (empty ($error)) {
        // Substitute $_POST for $_SESSION
        $_SESSION ['join'] = $_POST;
        header ('Location: find.php');
        exit ();
    }
}
?><! DOCTYPE html><html><head><meta charset = "UTF-8"><meta name = "viewport" content = "width = device-width, initial-scale = 1.0"><link rel = "stylesheet" href = "../ styl.css" /><title>Absolutely no smoking!</title></head><body>        <!-==== header === --->    <header>                                                                                                        <p>                   Click here for how to use               </p>                </header>       New registration                   <form action = "" method = "POST">            <!-Read name and password with $_POST->            <p>Name:</p>            <input type = "text" name = "name" value = "<? php print (htmlspecialchars ($_ POST ['name']],

ENT_QUOTES));?>">            <? php if ($error ['name'] ===' blank') :?>            <p>Please enter your name</p>            <? php endif;?>
              <p>Password:</p>            <input type = "text" name = "password" value = "<? php print (htmlspecialchars ($_POST ['password']],

ENT_QUOTES));?>">            <? php if ($error ['password'] ==='length') :?>            <p>Enter the password with at least 4 characters</p>            <? php endif;?>            <? php if ($error ['password'] ===' blank') :?>            <P>Please enter your password</P>            <? php endif;?>            <? php if ($error ['password'] ==='duplicate') :?>                <p>The specified password is already in use</p>            <? php endif?>            <br>            <input type = "submit" value = "Confirm input">        </form>        </body></html>
=== find.php ===<? php
// Bring information in session
session_start ();
require ('../conect.php');
// Return to new_log.php if session ['join'] is not set
if (! isset ($_SESSION ['join'])) {
    header ('Location: new_log.php');
    exit ();
}
// Save name and password when form post is sent
if (! empty ($_POST)) {
    $statement = $db->prepare ('INSERT INTO member SET name = ?, password =?');
    $statement->execute (array (array (
        $_SESSION ['join'] ['name'],

$_SESSION ['join'] ['password']
    ));
    // Clear session ['join'] and transition to ok.php
    unset ($_SESSION ['join']);
    header ('Location: ok.php');
    exit ();
}
?><! DOCTYPE html><html><head><meta charset = "UTF-8"><meta name = "viewport" content = "width = device-width, initial-scale = 1.0"><link rel = "stylesheet" href = "../ styl.css" /><title>Absolutely no smoking!</title></head><body>        <!-==== header === --->    <header>                                                                                                                        <p>                   Click here for how to use               </p>                </header>       Is the registration information correct here?           <form action = "" method = "POST">            <input type = "hidden" name = "action" value = "submit" />            <!-Output name and passsword with $_SESSION->                                <P>Name:</P>                <? php print (htmlspecialchars ($_SESSION ['join'] ['name'],

ENT_QUOTES));?>                <br>                <P>Password:</P>                <? php print (htmlspecialchars ($_SESSION ['join'] ['password'],

ENT_QUOTES));?>                            <P>If there are no mistakes in the entered information, click Register</P>                                   Rewrite                   <input type = "submit" value = "submit">                        </form></body></html>
=== login.php ===<? php
    // Bring information in session
    session_start ();
    require ('conect.php');

    if (! empty ($_POST)) {
        // What to do when $_POST is not empty
        if ($_POST ['name']! ==''&&$_POST ['password']! =='') {
            $login = $db->prepare ('SELECT * FROM member WHERE name =? AND password =?');
            $login->execute (array (array (
                $_POST ['name'],


                $_POST ['password']
            ));
            $member = $login->fetch ();
            if ($member) {
                $_SESSION ['id'] = $member ['id'];
                $_SESSION ['time'] = time ();
                // Save login information in cookie for 3 days
                if ($_ POST ['save'] ==='on') {
                    setcookie ('password', $_POST ['password'],time () + 60 * 60 * 24 * 3);
                }
                header ('Location: check.php');
                exit ();
            } else {
                $error ['login'] ='failed';
            }
        // Processing when $_POST is empty
        } else {
            $error ['login'] ='blank';
        }
    }
?><! DOCTYPE html><html>    <head>        <meta charset = "utf-8">        <link rel = "stylesheet" href = "styl.css" />        <meta name = "viewport" content = "width = device-width, initial-scale = 1.0">        <title>Absolutely! No smoking! !!</title>    </head>    <body>                        <header>                <!-=== header ===->                                                                                                                                                  <p>                               Click here for new registration                           </p>                                                        </header>            <!-Center->                                  Make a big difference in your life with "No Smoking"
                              <P>                  30-day smoking cessation challenge
              </P>                                <!-Action is empty and the input information is true/false in php->                <form action = "" method = "POST">                                                <p>Name:</p>                        <input type = "text" name = "name" value = "<? php echo (htmlspecialchars ($_POST ['name']));?>"><br>                        <? php if ($_ POST ['name'] ===' blank') :?>                        <p>Please enter the correct name and password</p>                        <? php endif;?>                        <p>Password:</p>                        <input type = "password" name = "passwoed" value = "<? php echo (htmlspecialchars ($_POST ['password']));?>"><br>                        <? php if ($error ['login'] ==='failed') :?>                        <p>Login failed</p>                        <? php endif;?>                                            <br>                    <br>                    <input type = "submit" value = "login" name = "">                </form>                                </body></html>