Connecting DB and Website..

Adem

Member
Aug 8, 2012
170
7
Hey can someone teach me on how to connect my database (user&login) and the login/register on my website. Im using mysql and I wanna know how revcms do it etc.

Thanks.
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Hey can someone teach me on how to connect my database (user&login) and the login/register on my website. Im using mysql and I wanna know how revcms do it etc.

Thanks.
All you have to do is create a database connect and run your queries out of it.

PHP:
$server = "localhost";
$username = "username";
$password = "password";

$connection = new mysqli($server, $username, $password);

if($connection->connect_error){
  die("Connection failed: " . $conn->connect_error);
}

Then:
PHP:
$query = "SELECT * FROM USERS WHERE `username` = '".$_POST['username']."' AND `password` = '".MD5($_POST['password'])."' LIMIT 1";
$results = mysqli->query($query);
if(mysqli_num_rows($results) > 0){
//Login
$_SESSION['user'] = $_POST['username'];
}

Pretty much just going to do this.. and same with register... This was off the top of my head so :) Don't copy and paste cause no promises.
 

BIOS

ಠ‿ಠ
Apr 25, 2012
906
247
All you have to do is create a database connect and run your queries out of it.

PHP:
$server = "localhost";
$username = "username";
$password = "password";

$connection = new mysqli($server, $username, $password);

if($connection->connect_error){
  die("Connection failed: " . $conn->connect_error);
}

Then:
PHP:
$query = "SELECT * FROM USERS WHERE `username` = '".$_POST['username']."' AND `password` = '".MD5($_POST['password'])."' LIMIT 1";
$results = mysqli->query($query);
if(mysqli_num_rows($results) > 0){
//Login
$_SESSION['user'] = $_POST['username'];
}

Pretty much just going to do this.. and same with register... This was off the top of my head so :) Don't copy and paste cause no promises.
Why use MySQLi when you are going to throw away it's biggest advantage, prepared statements?

Concatenating raw datanadeshotFace
MD5 nadeshotBruh
 

Users who are viewing this thread

Top