当我知道它位于数据库中的事实时,为什么返回的回声不正确?

时间:2015-04-23 22:37:16

标签: php arrays database if-statement echo

所以我编写了一个我在网上找到的用户登录信息和youtube,以帮助我根据自己的喜好自定义我的网站。但是一切都工作正常它的旧链接,所以我知道时间已经改变..但所有的研究我已经完成..和编码我做了我不明白为什么它不起作用..这里是包括编码..

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

这是index.php文件..

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

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

$errors = array();
?>

这是init.php文件...

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

这是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;
}
?>

那就是user.php文件......

<?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.";
  }
}
?>

最后是login.php ..

我知道有一个事实我手动输入两个记录...

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

应该带回&#34; Exists&#34;相反它带回来了#34;不存在&#34;所以我不知道我是否没有正确地将connect.php设置到数据库..或者我在某处错字?任何帮助将是伟大的ty :)&lt; 3

0 个答案:

没有答案