我正在按照本教程創建我正在使用的註冊數據庫。我回過頭來看視頻,然後看着評論,試圖找到解決我的問題的方法。mysql錯誤顯示不正確
我遇到的問題是,我設置的錯誤不能正確顯示我的數據庫。我有一個用戶名爲'lowheartrate',但是當我把它放在用戶名字段中並嘗試用它登錄時,它告訴我我的其他錯誤之一,
「我們找不到那個用戶名。註冊?」
很高興有效,但我需要其他人的工作。特別是不能工作了的有以下錯誤:
The 'user_active' error.
The 'user_exists' error.
這是與我有問題附屬代碼:
我的login.php它顯示了代碼的錯誤:
是他們連接在一起,並告訴它做的users.php代碼:
的general.php:
的的init.php:
在users.php更好看:
<?php
function user_exists($username) {
$username = sanitize ($username);
return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username'"),0) == 1) ? true : false;
}
function user_active($username) {
$username = sanitize ($username);
return (mysql_result(mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `username` = '$username' AND `active` = 1"), 0) == 1) ? true : false;
}
?>
在login.php中更好看:
<?php
include ('core/init.php');
if (empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username) == true || empty($password) == true) {
$errors[] = 'You need to enter a username and password.';
} else if (user_exists($username) == false) {
$errors[] = 'We can\'t find that username. Have you registered?';
} else if (user_active($username) == false) {
$errors[] = 'You haven\'t activated your account.';
} else {
// here
}
print_r($errors);
}
?>
一個更好看的init.php:
<?php
session_start();
error_reporting(0);
require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';
$errors = array();
?>
一個更好的看general.php:
<?php
function sanitize($data) {
return mysql_real_escape_string($data);
}
?>
一個更好的看connect.php:
<?php
$connect_error = 'Sorry we\'re experiencing connection issues.';
$con = mysqli_connect('localhost','root','');
mysqli_select_db($con,'lr') or die($connect_error);
?>
一看錶(登錄。PHP的小部件):
<div class="widget">
<h2>Returning Member?</h2>
<div class="inner">
<form action="login.php" method="post">
<ul id="login">
<li>
<input type="text" name="username" placeholder="Username" autofocus >
</li>
<li>
<input type="password" name="password" placeholder="Password" >
</li>
<li>
<input type="submit" value="Log in" >
</li>
<li>
<a href="register.php">Create an Account</a>
</li>
</ul>
</form>
</div>
</div>
不知道它的問題,但在此處,它被顯示在index.php:
<?php
$pageTitle = 'gLounge - Welcome to gLounge!';
include('includes/php/header.php');
?>
<!-- Middle content section -->
<div class="middle">
<div class="container">
<div class="col-md-9 content">
<h2>Use gLounge42 as your new source to connect with fellow gamers. We have plenty for you to look at.</h2>
<p>
gLounge42 allows all types of gamers on all types of consoles/platforms connect with each other with
unlimited amount of reasons to do so. Here at gLounge42 you can chat with them and go as far as posting
in forums to get members for you Call of Duty clan. Possibilities are endless so go ahead and get your
account setup now with gLounge42!
</p>
<div class="to-tutorial">
<p><strong>Register an Account to get started:</strong></p>
<a href="register.php" class="btn btn-success">Register</a>
</div>
</div>
<!-- Includes the login widget on the top right side of page -->
<?php include('includes/widgets/login.php');?>
<!-- Includes the side navigation area -->
<?php include('includes/php/sideNavigation.php');?>
</div>
</div>
<?php
include('includes/php/footer.php')
?>
數據庫的元素,我正在使用:
個
連接到數據庫中的用戶:
如果需要任何更多信息,請讓我知道。
此致敬禮,
科迪
@ Arif_suhail_123我仍然得到同樣的錯誤,當我用2代替3 '=' 代替的跡象。沒有拿起user_active不幸 – cscodismith 2014-10-11 05:31:42
@ Arif_suhail_123是的,仍然沒有找到我的解決方案。會愛你的輸入請 – cscodismith 2014-10-11 06:21:38
@ Arif_suhail_123當我添加你給我的代碼並繼續到login.php它沒有任何錯誤代碼什麼都不是什麼好事,因爲我繼續登錄login.php,甚至沒有把一個用戶名或密碼,它並沒有給我一個錯誤代碼。 – cscodismith 2014-10-11 06:32:42