The errors are:
Warning: mysql_result() expects parameter 1 to be resource, boolean given in /home/tumaback/public_html/core/inc/users.inc.php on line 9
Warning: Cannot modify header information - headers already sent by (output started at /home/tumaback/public_html/core/inc/users.inc.php:9) in /home/tumaback/public_html/index.php on line 32
Here is my users.inc.php code:
<?php // Checks if the given user name exists in the database. function user_exists($user){ $user = mysql_real_escape_string($user); $total = mysql_query("SELECT COUNT (`user_id`) FROM `users` WHERE `user_name`= '{$user}'"); return (mysql_result($total, 0) == '1') ? true : false; echo mysql_error(); } // Checks if the given username and password combination is valid. function valid_credentials($user, $pass){ $user = mysql_real_escape_string($user); $pass = sha1($pass); $total = mysql_query("SELECT COUNT (`user_id`) FROM `users` WHERE `user_name`= '{$user}' AND `User_password` = '{$pass}' "); return (mysql_result($total, 0) == '1') ? true : false; } // Adds a user to the database. function add_user($user, $pass){ $user = mysql_real_escape_string(htmlentities($user)); $pass = sha1($pass); mysql_query("INSERT INTO `users` (`user_name`, `user_password`) VALUES ('{$user}', '{$pass}')"); } ?>And my init.inc.php
<?php session_start(); $exceptions = array('index','login'); $page = substr(end(explode('/',$_SERVER['SCRIPT_NAME'])), 0, -4); if (in_array($page, $exceptions) === false){ if (isset($_SESSION['username']) === false){ header('Location: login.php'); die(); } } mysql_connect('localhost', 'accountname', '*********'); mysql_select_db('tumaback_user_system'); $path = dirname(__FILE__); include("{$path}/inc/users.inc.php"); ?>Edit: Also heres my index.php
<?php error_reporting(E_ALL); ini_set('display_errors', 1); include('core/init.inc.php'); $errors = array(); if (isset($_POST['username'], $_POST['password'], $_POST['repeat_password'])){ if (empty($_POST['username'])){ $errors[] = 'The username cannot be empty.'; } if (empty($_POST['password']) || empty($_POST['repeat_password'])){ $errors[] = 'The password cannot be empty.'; } if ($_POST['password'] !== $_POST['repeat_password']){ $errors[] = 'Passwords dont match!'; } if (user_exists($_POST['username'])){ $errors[] = 'Username already exists!'; } if (empty($erros)){ add_user($_POST['username'], $_POST['password']); $_SESSION['username'] = htmlentities($_POST['username']); header('Location: protected.php'); die(); } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>NewCo | Sign Up</title> <link rel="shortcut icon" href="favicon.ico"> <link href='http://fonts.googleapis.com/css?family= ... cento+Sans' rel='stylesheet' type='text/css'> <link href="/ext/style/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="contact"> <h1>Under Construction.</h1> <?php if (empty($errors) === false){ ?> <ul> <?php foreach ($errors as $error){ echo "<li>{$error}</li>"; } ?> </ul> <?php } ?> <form action="/" method="post"> <input type="text" name="username" id="username" placeholder="Username" /> <input type="password" name="password" id="password" placeholder="Password" /> <input type="password" name="repeat_password" id="repeat_password" placeholder="Re-Type Password"> <input type="submit" value="Submit" /> </form> </div> </body> </html>Please help!