1

So i'm coding a user login that i found online and youtube to help customize to my own liking for my website. however everything works fine its an old link so i know times have changed.. but with all the research i've done.. and the coding i did i dont get why it doesnt work.. here are the included coding..

<?php 
include 'core/init.php';
include 'includes/overall/header.php';?>
  <h1>Home</h1>
  <p>Just a template</p>
<?php include 'includes/overall/footer.php';?>

that is the index.php file..

<?php
session_start();
error_reporting(0);

require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';

$errors = array();
?>

that is the init.php file...

<?php
$connect_error = 'Error message';
$con = mysqli_connect('localhost','root','********');
mysqli_select_db($con,'millcitycannabis') or die($connect_error);
?>

that's the connect.php...

<?php 
function user_exists($username) {
  $username = sanitize($username);
  return (mysql_result(mysql_query("SELECT COUNT('user_id') FROM users WHERE user_name = '$username'"), 0) == 1) ? true : false;
}
?>

thats the user.php file...

<?php
include 'core/init.php';

if (user_exists('Joshua') === true) {
  echo 'Exists';
} else {
  echo 'Does not exist';
}
die();

if (empty($_POST) === false) {
  $username = $_POST['username'];
  $password = $_POST['password'];

  if (empty($username) || empty($password)) {
    $errors[] = 'You need to enter a Username and Password.';
  } else if (user_exists($username) === false) {
    $errors[] = "User name not found. Please check and try again.";
  }
}
?>

and finally the login.php..

i know for a fact there are two records i manually put in...

if (user_exists('Joshua') === true) {
  echo 'Exists';
} else {
  echo 'Does not exist';
}
die();

should bring back "Exists" instead it brings back "Does not exist" so i dont know if i didnt set up the connect.php to the database correctly.. or did i typo somewhere? any help would be great ty :) <3

potashin
  • 44,205
  • 11
  • 83
  • 107
  • 2
    You can't mix `mysql` and `mysqli` functions. If you use `mysqli_connect`, you have to use `mysqli_query` and other `mysqli_XXX` functions. – Barmar Apr 23 '15 at 22:39
  • possible duplicate of [MySQLi equivalent of mysql\_result()?](http://stackoverflow.com/questions/2089590/mysqli-equivalent-of-mysql-result) – Barmar Apr 23 '15 at 22:42
  • Do NOT use any mysql_* functions, they are deprecated and you should use prepared statements or mysqli_* functions. – Xander Luciano Apr 23 '15 at 22:45
  • I tried to add all mysqli codes.. i use dreamweaver CS6 right now and when i do that it turns from blue to black.. so it doesnt look like a correct function. and when i try it and run it anyways on my localserver it comes back a blank page.. same error code.. – Joshua Martinez Apr 23 '15 at 22:46
  • Stop using `error_reporting(0);` when you're developing. That should only be considered in production use. You should have `E_ALL`. – Devon Bessemer Apr 23 '15 at 23:17
  • apparently.. im very outdated.. and need to refigure out this change in mysql and php programming.. sigh.. – Joshua Martinez Apr 23 '15 at 23:41
  • Joshua, I recommend you move forward with using PDO instead of mysqli. This is a good tutorial on how to set up a PDO. It seems you already have the database side set up so connecting and querying shouldn't be too hard: http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059 – Walker Boh Apr 24 '15 at 03:32

0 Answers0