All you have to do is create a database connect and run your queries out of it.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.
$server = "localhost";
$username = "username";
$password = "password";
$connection = new mysqli($server, $username, $password);
if($connection->connect_error){
die("Connection failed: " . $conn->connect_error);
}
$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'];
}
Why use MySQLi when you are going to throw away it's biggest advantage, prepared statements?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.
MD5 is horrible, and I don't use it but I couldn't be asked to do anything else, I coded that off the top of my head xDWhy use MySQLi when you are going to throw away it's biggest advantage, prepared statements?
Concatenating raw data
MD5
Never execute an SQL query with $_POST data that has not been filtered.MD5 is horrible, and I don't use it but I couldn't be asked to do anything else, I coded that off the top of my head xD
Yes I know, I was giving an example typed on my phone , and I was really trying to actually code it for him I was just showing him how its done.Never execute an SQL query with $_POST data that has not been filtered.