Sign in or Sign up

PHP + Mysql register with php
Started by Epic


Rate this topic
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5


16 posts in this topic
[IDLE]Epic Offline
Programmers
***


IDLE
Posts: 147
Threads: 20
Joined: Thu Apr 2017
Reputation: 7

CZPoints: 0 CZP
Contributor
04-22-2017, 06:15 PM -
#1
hi my name is epic, and since I love to code in php and mysql.
I thought i would share with you how to make a register page that sends the register info to mysql.
this method also logs ips. can be removed if necessary.

first to start of with is the connect to mysql: call this file db.php, change the mysql information down below the host user and password, database.
Code:
<?php
class db
{
    public $host;
    public $user;
    public $pass;
    public $data;
    public $con;
    public $table;
    function db()
    {
        $this->host="your ip here.";
        $this->user="your username here";
        $this->pass="";
        $this->data="your database here";   
    }   
    public function connect()
    {
        $this->con=mysql_connect($this->host,$this->user,$this->pass);
        if(!$this->con)
        {
            echo mysql_error();
        }
        $sel=mysql_select_db($this->data, $this->con);
        if(!$sel)
        {
            echo mysql_error();
        }
    }
    public function insert($username,$email,$password,$ip)
    {
        $sql=mysql_query("INSERT INTO users(username, email, password, ipaddress) VALUES('$username', '$email', '$password', '$ip')");
        if(!$sql)
        {
            echo mysql_error();
        }
    }
}
?>
save this file, now lets move to the process.php
make a php file called process.php and paste in this code.
Code:
<?php
    include'inc/db.php';
    $username=$_POST['Username'];
    $email=$_POST['Email'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $password=$_POST['Password'];
    $n=new db();
    $n->connect();
    $n->insert($username,$email,$password,$ip);
    header("Location: index.php");
?>
you dont need to change anything here exept the header("Location: index.php"); part.
now save this file and lets move over to the register.php
Code:
<form action="process.php" method="post">
    <div class="yourclasshere">
    <input class="sectiondiv2" name="Username" placeholder="Username" type="text" />
    </div>
        <br><br>
        <div class="yourclasshere">
    <input class="sectiondiv2" name="Email" placeholder="Email" type="text" />
    </div>
    <br><br>
    <div class="yourclasshere">
    <input class="yourclasshere" name="Password" placeholder="Password" type="text" />
    </div>
    <!--<label><input name="Checkbox1" type="checkbox"> Remember Me?</label>--->
    <br><br>
    <center><button type="submit" value="submit" name="submit" class="login">Register</button><center>
    <br>
    <center><a href="index.php">Already have an account?</a></center>
    <br><br>
    </form>
now save this file, now we need to start on the database part.
you would need heidisql for this and xampp:
https://www.apachefriends.org/index.html
https://www.heidisql.com/

now lets make the database:
first start by starting xampp and starting apache and mysql.
[Image: 61948f54b6c1696da95bc0e62cd8f11b.png]
next open heidisql.

[Image: 72bd8904a47fd4ba6f6869b78d897c5c.png]
fill in your mysql login credentials.
then click open.

next right click your main sql, in my case its the unnamed.
[Image: 8a7a902fc7199542bd33487be56363d6.png]
next hover over the main sql. then hover over create new, then click database.
then give that database a name, cause that database you will need it for the configs on php.
now right click on that database you just created. and create a table.
call that table users. after that you will see this:
[Image: aae755f836bbf182f50a98e4017ce1e8.png]
the part where it says columns: and then a add button click that button and name it id, after you named it id, go to here:
[Image: 0c7ff693389e16af0df36b58ea2cb7db.png]
and click auto_increment. then click ok.
now you need to add 3 more columns.
one named username, email, and password, and ipaddress.
save all of them, after you done that do this following step for the 4 columns.
https://i.gyazo.com/6ff8b291acf64d4157fa...a3b7c5.mp4 its a gif so i can post it so just click and come back after.
after you done that lets make the id the index key.
to make the key, do this.
click on indexes and press add:
[Image: aa7b379442a6e5cae82aa1dd2afb9f6e.png]

after you add a index key right click it.
now click add column shift. and the if will pop remember to select id before clicking add column shift.

now we are done with the mysql part.

now we need to change the information in the db.php file
localhost is what im using to make this on so i have to put host as localhost.
username is root on my side but use your mysql username and password
same with password.
database is the database name you created. not the table the database.
Code:
$this->host="localhost";
        $this->user="your username here";
        $this->pass="";
        $this->data="your database here";


tutorial finished.
pm me for help, ready to assists.
also say something if it doesnt work if i missed something.


Save your negative comments
say something positive!
This post was last modified: 04-22-2017, 07:20 PM by Epic.
[Image: PMBDPha.png]
ScorpionOfWar Offline
Super Moderator
******


Super Moderators
Posts: 239
Threads: 11
Joined: Fri Mar 2017
Reputation: 14

CZPoints: 38 CZP
Contributor
04-23-2017, 12:56 AM -
#2
Nice tutorial man! I like it, good to know that its that easy with HeidiSql
[Image: PWXNX5p.gif]

Discord - @ScorpionOfWar#0001
[IDLE]Epic Offline
Programmers
***


IDLE
Posts: 147
Threads: 20
Joined: Thu Apr 2017
Reputation: 7

CZPoints: 0 CZP
Contributor
04-23-2017, 06:23 AM -
#3
(04-23-2017, 12:56 AM)ScorpionOfWar Wrote: Nice tutorial man! I like it, good to know that its that easy with HeidiSql

glad you liked it :)
[Image: PMBDPha.png]
Mystique Offline
Junior Member
**


Registered
Posts: 42
Threads: 5
Joined: Sun Apr 2017
Reputation: 0

CZPoints: -5 CZP
04-23-2017, 11:26 AM -
#4
Nice tutorial!

Will help people out for sure!
[Image: d1wl9Az.png]
[IDLE]Epic Offline
Programmers
***


IDLE
Posts: 147
Threads: 20
Joined: Thu Apr 2017
Reputation: 7

CZPoints: 0 CZP
Contributor
04-23-2017, 12:27 PM -
#5
(04-23-2017, 11:26 AM)Mystique Wrote: Nice tutorial!

Will help people out for sure!

thanks. :)
[Image: PMBDPha.png]
Corruption Offline
Administrator
*******


Administrators
Posts: 291
Threads: 67
Joined: Fri Mar 2017

CZPoints: 119 CZP
04-23-2017, 12:48 PM -
#6
Very nice but wont this store passwords in plain text /;
[IDLE]Epic Offline
Programmers
***


IDLE
Posts: 147
Threads: 20
Joined: Thu Apr 2017
Reputation: 7

CZPoints: 0 CZP
Contributor
04-23-2017, 01:23 PM -
#7
(04-23-2017, 12:48 PM)Corruption Wrote: Very nice but wont this store passwords in plain text /;

yeah, but you can add sha512 or any other hash.
[Image: PMBDPha.png]
Mystique Offline
Junior Member
**


Registered
Posts: 42
Threads: 5
Joined: Sun Apr 2017
Reputation: 0

CZPoints: -5 CZP
04-24-2017, 02:28 PM -
#8
I just realized there is no login page, I was gonna make a fast remake for bcrypt hash.
[Image: d1wl9Az.png]
[IDLE]Epic Offline
Programmers
***


IDLE
Posts: 147
Threads: 20
Joined: Thu Apr 2017
Reputation: 7

CZPoints: 0 CZP
Contributor
04-24-2017, 02:41 PM -
#9
(04-24-2017, 02:28 PM)Mystique Wrote: I just realized there is no login page, I was gonna make a fast remake for bcrypt hash.

i have the login page code ready, just havent uploaded the tutorial yet.
[Image: PMBDPha.png]
Mystique Offline
Junior Member
**


Registered
Posts: 42
Threads: 5
Joined: Sun Apr 2017
Reputation: 0

CZPoints: -5 CZP
04-24-2017, 02:51 PM -
#10
(04-24-2017, 02:41 PM)Epic Wrote:
(04-24-2017, 02:28 PM)Mystique Wrote: I just realized there is no login page, I was gonna make a fast remake for bcrypt hash.

i have the login page code ready, just havent uploaded the tutorial yet.

Oh :) We'll I don't wanna release my edit until there is a login page due to them might not know how to verify bcrypt.
[Image: d1wl9Az.png]




Users browsing this thread: 1 Guest(s)