Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Read functions saves data into the database rather than reading it and loging me

$
0
0

I am fairly new to PHP and I'm doing a simple login and sign up form for a social website I am making. Im coding on VS studio code and using different files such as .html , .css and .php. Im still figuring out on how to link php and html together but I successfully got my sign up to work and it registers my data into my database (im using XAMPP). the problem occured when i was trying to login in.

my sign up and login form are on the same html file as im using some js to make it visible and hidden when the user either clicks on login or register.

<form method="post" action="/Php/login.php"><!-- Input box for email for login panel  --><div class="input_box"><span class="icon"><i class="bx bxs-envelope"></i></span><input name="email" type="email" required placeholder="email" /></div><!-- input box for password for login panel --><div class="input_box"><span class="icon"><i class="bx bxs-lock-open"></i></span><input          name="password"          type="password"          required          placeholder="Password?"        /></div>
<?phpsession_start();include("/xampp/htdocs/FinalYearProject/Php/signup.php");include("/xampp/htdocs/FinalYearProject/Php/connect.php");class Login{    private $Error = "";    public function CheckLogin($data)    {        $email = addslashes($data['email']);        $password = addslashes($data['password']);        //SQL QUERY to get email         $query = "SELECT * FROM users WHERE email = '$email' limit 1";        $DB = new ConnectDB();        $result =  $DB->read($query);        // password check and more security         if ($result) {            $row = $result[0];            if ($password == $row['password']) {                //creating a session to maintain info for different pages/move info for the same website                $_SESSION['gameimperiumUserID'] = $row['UserID'];            } else {                $this->Error .= "Invalid Password<br>";            }        } else {            $this->Error .= "Invalid Email<br>";        }        return $this->Error;    }}if ($_SERVER['REQUEST_METHOD'] == 'POST') { // information contained by the server about the server    $login = new Login();    $result = $login->CheckLogin($_POST);    if ($result != "") {        echo "<div style = 'text-align: center; font-size: 12px ; color:white; background-color: grey;'>";        echo "the follow errors occured<br>";        echo $result;        echo "</div>";    } else {        header("Location: http://localhost/Html/Profile.html");        die;    }}

I have different files for signup and connect to DB. The main problem is when i enter data into the login form and submit it , the data goes into the database and makes a new entry for a new user.I tried changing names and variables, getting everything under a single file and changing include files but none work. I want the php file to successfully read data from the database and redirect me to my header location and do this without making a new entry in the database for a new user


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>