Simple PHP - fill in ('localhost' , 'username , 'password' , 'database_name')
First, thanks goes out to both Nancy O. & osgood_ in helping me figure
out how PHP's and MySQLi work but I still have a long way to go. As of now I'm working on a simple PHP script I attainted through Nancy O. at http://stackoverflow.com/questions/24397969/simple-but-secure-user-registration-with-php-and-mysqli
So far it is working well and I made a few changes to give it the type of look I want....
However, one little problem arises: WHERE exactly do I insert my ('localhost' , 'username , 'password' , 'database_name') at? I tried to find a "$con = mysqli_connect" followed by but couldn't find exactly that anywhere. Well below I put a copy of the beginning of the script where I assume it will go and if anyone know where I should put that I would love to know. Thanks.
<html>
<head>
<meta charset="utf-8">
<title>Login & Registration System Page</title>
</head>
<?php
include('config.php'); // Database connection and settings
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(isset($_POST['register'])){
$name = trim(mysqli_escape_string($conn,$_POST['username'])); <-here?
$first_name = trim(mysqli_escape_string($conn,$_POST['first_name'])); <-here?
$last_name = trim(mysqli_escape_string($conn,$_POST['last_name'])); <-here?
$display_name = trim(mysqli_escape_string($conn,$_POST['display_name'])); <-here?
$email = trim(mysqli_escape_string($conn,$_POST['email'])); <-here?
$passwords = trim(mysqli_escape_string($conn,$_POST['password'])); <-here?
$password = md5($passwords);
$query_verify_email = "SELECT * FROM users WHERE email ='$email'";
$verified_email = mysqli_query($conn,$query_verify_email) or die("Error: ".mysqli_error($conn)); <-here?
if (!$verified_email) {
echo ' System Error';
}
if (mysqli_num_rows($verified_email) == 0) { <-here?
// Generate a unique code:
$hash = md5(uniqid(rand(), true));
$query_create_user = "INSERT INTO users (username, email, password, hash,first_name,last_name,display_name,pic,gender,isactive)
VALUES ( '$name', '$email', '$password', '$hash','$first_name','$last_name','$display_name','','',0)"; <-here
$created_user = mysqli_query($conn,$query_create_user) or die("Error: ".mysqli_error($conn)); <-here
if (!$created_user) {
echo 'Query Failed ';
}
if (mysqli_affected_rows($conn) == 1) { //If the Insert Query was successfull.
$subject = 'Activate Your Email';
$headers = "From: admin@infotuts.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$url= 'verify.php?email=' . urlencode($email) . "&key=$hash";
$message ='<p>To activate your account please click on Activate buttton</p>';
$message.='<table cellspacing="0" cellpadding="0"> <tr>';
$message .= '<td align="center" width="300" height="40" bgcolor="#000091" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;
color: #ffffff; display: block;">';
$message .= '<a href="'.$url.'" style="color: #ffffff; font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none;
line-height:40px; width:100%; display:inline-block">Click to Activate</a>';
$message .= '</td> </tr> </table>';
mail($email, $subject, $message, $headers);
echo '<div class="alert alert-success">A confirmation email
has been sent to <b>'. $email.' </b> Please click on the Activate Button to Activate your account </div>';
} else { // If it did not run OK.
echo '<div class="alert alert-info">You could not be registered due to a system
error. We apologize for any
inconvenience.</div>';
die(mysqli_error($conn));
}
}
else{
echo '<div class="alert alert-danger">Email already registered</div>';}
}
?>
(the rest of the script would be below and if anyone wants to see the rest of it feel free to let me know)
