I have been looking for a mistake in my php and mysql for the past 5 hours. I have no clue what I have done wrong or if there is just a problem with my mamp. I think it may be a problem with my mamp. This is where I believe the problem would be taking place. But the problem is that now every page comes up blank. Thanks.
site/core/init.php
<?php
session_start();
error_reporting(0);
require 'database/connect.php';
require 'database/general.php';
require 'functions/users.php';
$errors = array();
?>
site/core/functions/users.php
<?php
function user_exists($username) {
$username = sanitize($username);
$query = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'username' = '$username'");
return (mysql_result($query, 0) == 1 ) ? true : false;
}
?>
site/includes/widgets/logins
<aside>
<div class = "rightsidebar">
<h2>Log in/Register</h2>
<form action = "login.php" method = "post">
<ul id = ".login">
<li>
Username:<br>
<input type = "text" name = "username">
</li>
<li>
Password:<br>
<input type = "password" name = "password">
</li>
<li>
<input type = "submit" value = "Log In">
</li>
<li>
<a href = "register.php"><p>Register</p></a>
</li>
</ul>
</form>
</div>
</aside>
site/core/database/connect.php
<?php
mysql_connect('localhost', 'root', 'root');
mysql_select_db('lr');
?>
site/core/functions/general.php
<?php
function sanitize($data) {
return mysql_real_escape_string($data);
}
?>
site/login.php
<?php
include 'core/init.php';
if (user_exists('ben') === true) {
echo 'exists';
}
die();
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 ca\'nt find that username. Have you registered?';
}
}
?>
In query table name and column name should not be wrapped with '
(quot). Either you can use `
or nothing.
$query = mysql_query("SELECT COUNT(user_id) FROM users WHERE username = '$username'");
Kindly track your errors starting from the first included filerequire 'database/connect.php';
. Try or die(mysql_error());
after connection , selecting your db and your query. Try to use echo 'a'; echo 'b'; echo 'c';
in the rest of files to catch where is the die
or error
exactly occurs. Try to echo your $_POST
data to check if it comes true. Try to check your network panel
in your browser to catch the request that made that error.
Syntax error in login.php. No space allowed between OR operator syntax.
if(empty($username) === true | | empty($password) === true) {
Should be
if(empty($username) === true || empty($password) === true) {