PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Oct 24, 2017 2:53 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Oct 06, 2017 7:24 pm 
Offline
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 171
Folks!

I really need the following code converted to mysqli procedural from pdo oop. Once that is done, my 7 months project will come to an end. And, I can move-on to learning pdo. Right now, can't afford to jump into pdo without finishing my current project.
So, who will help me convert ? Other newbies would learn from your conversion.

Thanks!

Syntax: [ Download ] [ Hide ]
<?php
 
/*
ERROR HANDLING
*/

declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
 
include 'config.php';
 
// check if user is already logged in
if (is_logged() === true)
{
        //Redirect user to homepage page after 5 seconds.
        header("refresh:2;url=home.php");
        exit; //
}

if (
        array_key_exists('login_username_or_email', $_POST) &&
        array_key_exists('login_password' , $_POST)
) {
        $usernameoremail = trim($_POST["login_username_or_email"]); //
        $password = $_POST["login_password"];

        // don't bother trimming, they can't enter it right, don't let them log in!

        $stmt = $conn->prepare('
                SELECT ids, usernames, passwords, emails, accounts_activations_statuses
                FROM users
                WHERE '
. (
                        strpos($usernameoremail, '@') === false) ? 'usernames' : 'emails'
                ) . ' = ?
        '
);
       
        $stmt->bind_param('s', $_POST['login_username_or_email']);
        $stmt->execute();
        $stmt->bind_result(
                $db_id, $db_username, $db_password, $db_email,
                $db_account_activation_status
        );
       
        if (
                $stmt->fetch() &&
                password_verify($_POST['login_password'], $db_password)
        ) {
                echo '
                        <p>Login Successful</p>
                        <dl>
                                <dt>User Id</dt>
                                <dd>'
, $db_id, '</dd>
                                <dt>E-Mail</dt>
                                <dd>'
, $db_email, '</dd>
                                <dt>Username</dt>
                                <dd>'
, $db_username, '</dd>
                                <dt>Activation Stats</dt>
                                <dd>'
, $db_account_activation_status, '</dd>
                        </dl>
                '
;
        } else echo '<p>Invalid username or password</p>';
       
        $stmt->close();
       
} else echo '<p>Missing username or password</p>';
               
               
       
?>

<!DOCTYPE html>
<html>
<head>
<title><?php $site_name?> Member Login Page</title>
  <meta charset="utf-8">
</head>
<body>
<div class = "container">
<form method="post" action="">
        <h3><?= $site_name ?> Member Login Form</h3>
        <fieldset>
                <label for="login_name">Username/Email:</label>
                <input type="text" name="login_username_or_email" id="login_name">
                <br>
                <label for="login_pass">Password:</label>
                <input type="password" name="login_password" id="login_pass">
        </fieldset>
        <div class="submitsAndHiddens">
                <button type="submit">Login</button><br>
                <a href="login_password_reset.php">Forgot your Password?</a><br>
                <a href="register.php">Register New Account</a>
        </div>
</form>
</div>
</body>
</html>
 
 


Top
 Profile  
 
PostPosted: Sat Oct 07, 2017 3:49 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6391
Location: Montreal, Canada
UniqueIdeaMan wrote:
I really need the following code converted to mysqli procedural from pdo oop.

There's no PDO that I can see in there.

UniqueIdeaMan wrote:
Other newbies would learn from your conversion.

I don't know that I'd call actively making code worse a learning experience.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Oct 11, 2017 12:57 pm 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4296
Location: Sofia, Bulgaria
Celauran wrote:
UniqueIdeaMan wrote:
Other newbies would learn from your conversion.

I don't know that I'd call actively making code worse a learning experience.


+100

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
PostPosted: Wed Oct 11, 2017 3:45 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13434
Location: New York, NY, US
VladSun wrote:
Celauran wrote:
UniqueIdeaMan wrote:
Other newbies would learn from your conversion.

I don't know that I'd call actively making code worse a learning experience.


+100

:drunk:

It does look like the job of converting from mysqli procedural from mysqli OOP has been done. Excellent work!

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group