Hello I am making a email system for my school project. I wanting someone to help with getting it to display the password hash in the html document part. At the moment it doesn't display anything. Thank you Joshua
<?php require_once 'application/config/autoload.php';
$host= DB_HOST;
$username= DB_USER;;
$password= DB_PASS;
$db_name= DB_NAME;
$tbl_name= DB_TABLE;
$user_name = Session::get('user_name');
error_reporting(0);
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
$sql = "SELECT user_id,
user_name,
user_email,
user_password_reset_hash,
user_perm_level,
user_type,
user_active,
user_failed_logins,
user_last_failed_login
FROM $tbl_name WHERE user_name='$user_name'";
$result = mysql_query($sql);
if($result){
$link = "$result->user_password_reset_hash";
echo "<html>
<head>
<style>
body {
background-color: #fff;
font-family: Arial;
font-size: 14px;
color: #000;
padding: 0;
margin: 15;
}
h1 {
font-size: 40px;
}
h2 {
font-size: 20px;
}
</style>
<div>
<img src='logo.min.png' align='left'></p>
<h1 align='right'>Teacher Help</h1>
<h2 align='right'>Verify Email<br></h2>
<p>$link</p>
</div>
</head>
</html>"; } ?>
First, change your mysql_*
to mysqli_*
since it is already deprecated. Now, your could should be like this:
$link = mysqli_connect($host, $username, $password, $db_name);
$sql = "SELECT user_id,
user_name,
user_email,
user_password_reset_hash,
user_perm_level,
user_type,
user_active,
user_failed_logins,
user_last_failed_login
FROM $tbl_name WHERE user_name='$user_name'";
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
if ($row) {
$link = $row["user_password_reset_hash"];
// rest of code
}
You need to return it as an array
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$link = $row['user_password_reset_hash'];
Obviously mysql
is deprecated and you should consider using pdo
or mysqli
. As it's a project with a specific question, i have answered accordingly.
You've got to fetch the content of your result. Your code tells me, you want to use mysql_fetch_object
$result = mysql_query($sql);
if($result){
$row = mysql_fetch_object($result);
$link = $row->user_password_reset_hash;
echo $link;
// ...
I'm sorry that you learn at school to use those old deprecated mysql_* functions (see the red box in the linked manual page). You're better off with the mysqli extension or PDO, shown in the answer of lodev09. With PDO or mysqli you should use prepared statements with placeholders and put the input values to those placeholders to avoid sql injection.