Page 1 of 1

registry problems

Posted: Thu Sep 05, 2013 4:54 am
by doomrancher
Hello, I have recently watched PHP Tutorial: Register and Login (User Account System) [part 04] and have typed down everything that was written down but when I go to my registry.php page it says {$error}"; } ?> at the top, and if I dont fill out a row (which is supposed to bring up an error message) it still says {$error}"; } ?>. Also when I do fill out all the lines, the page doesn't go to protected.php but just refreshes the page. How do I fix this?

register.php

[syntax=php]<?php

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[] = 'Password verification failed.';
}

if (user_exists($_POST['username'])){
$errors[] = 'The username you entered is already taken.';
}

if (empty($errors){
add_user($_POST['username'], $_POST['password']);

$_SESSION['username'] = htmlentities($_POST['username']);

header('Location: protected.php');
die();
}
}

?>
<html>
<head>
<title>The Video Network</title>
</head>
<body bgcolor="59D7F0">
<div>
<?php

if (empty($errors) === false){
?>
<ul>
<?php

foreach ($errors as $error){
echo "<li>{$error}</li>";
}

?>
</ul>
<?php
}

?>
</div>

<table>
<tr>
<td><a href="homepage.php"><img src="ext\images\logo.png"></a></td>
<td><font size="5" color="59D7F0"><B>fille</B></font>
<td><img src="ext\images\topuploaders.png"></td>
<td><img src="ext\images\mostloved.png"></td>
<td><img src="ext\images\mostview.png"></td>
<td><font size="5" color="59D7F0"><B>fille</B></font>
<td><a href="login-register/login.php"><img src="ext\images\login.png"></a></td>
</tr>
</table>
<br>
<br>
<br>
<br>
<br>
<br>
<center>
<form action="" method="post">
<p>
<label for="username">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Username:</label>
<input type="text" name="username" id="username" />
</p>
<p>
<label for="password">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password:</label>
<input type="password" name="password" id="password" />
</p>
<p>
<label for="repeat_password">Repeat Password:</label>
<input type="password" name="repeat_password" id="repeat_password" />
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="Register" />
<p>
</form>
</center>
</body>
</html>[/syntax]

protected.php

[syntax=php]<?php include('core\init.inc.php'); ?>

<html>
<head>
<title>Login|The Video Network</title>
</head>
<body>
<p>
You are logged in as <?php ?>
</p>
</body>
</html>[/syntax]

init.inc.php

[syntax=php]<?php

session_start();

$exceptions = array('register', 'login');

if (in_array($page, $exceptions) === false){
if (isset($_SESSION['username']) === false){
header('location: login.php');
die();
}
}

mysql_connect('10.0.0.1', 'example_pass', 'example_pass');
mysql_select_db('user_system');

$path = dirname(_FILE_);

include("{$path}/inc/user.inc.php");

?>[/syntax]

user.inc.php

[syntax]<?php

// checks if the given username exists in the table
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;
}

// check if the given username and password combination is valid.
function valid_credentials($user, $pass){
$user = mysql_real_escape_string($user);
$pass = shal($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 = shal($pass);

mysql_query("INSERT INTO 'users' ('user_name', 'user_password') VALUES ('{$user}', '{$pass}')");
}

?> [/syntax]

Re: registry problems

Posted: Thu Sep 05, 2013 11:39 am
by Temor
can you post the code for ini.inc.php as well?
And please post the code here inside code tags. I don't like pastebin very much.

Re: registry problems

Posted: Thu Sep 05, 2013 1:11 pm
by doomrancher
ok i put up protected.php and init.inc.php as well

Re: registry problems

Posted: Thu Sep 05, 2013 1:22 pm
by Temor
Okay, the problem is instantly visible when you have syntax highlighting on.
You can clearly see that the highlighting breaks on line 9 in init.inc.php.
This is because you have one too many ending semicolons ( ; ). You should have one at the end of the line only. Remove the one after $_SERVER['SCRIPT_NAME']).

/Edit; I would also recommend you getting a text editor with syntax highlighting on, such as Notepad++

Re: registry problems

Posted: Fri Sep 06, 2013 12:24 am
by doomrancher
i fixed the thing with the init.inc.php file but it's still not working

Re: registry problems

Posted: Fri Sep 06, 2013 3:52 am
by ScTech
You are missing a semicolon after your header redirect.

Re: registry problems

Posted: Fri Sep 06, 2013 4:49 am
by doomrancher
in which script?

Re: registry problems

Posted: Fri Sep 06, 2013 7:08 am
by Temor
doomrancher wrote:in which script?

the same script.

Re: registry problems

Posted: Fri Sep 06, 2013 1:20 pm
by doomrancher
i put in the semicolon but it still does the same thing

Re: registry problems

Posted: Fri Sep 06, 2013 3:22 pm
by Temor
and what is this " same thing " ? "Not Working" is not very specific.

Do you get an error message?
Does it just refresh and not do anything?
Does it redirect you?

I can't guess my way to what's wrong.


Try turning on error reporting.
Put this in the top of init.inc.php:
[syntax=php]error_reporting(E_ALL);
ini_set('display_errors', 1);[/syntax]

Re: registry problems

Posted: Mon Sep 09, 2013 12:59 pm
by doomrancher
i don't get an error message, and it doesnt redirect me but it does refresh and not do anything.

plus the error reporting thing didnt work

Re: registry problems

Posted: Mon Sep 09, 2013 1:23 pm
by ScTech
Post user.inc.php please.

Re: registry problems

Posted: Fri Sep 13, 2013 3:31 am
by doomrancher
i did

Re: registry problems

Posted: Fri Sep 13, 2013 4:49 am
by ScTech
You posted init.inc.php. user.inc.php contains all the functions to make it work.

Re: registry problems

Posted: Fri Sep 20, 2013 5:20 am
by doomrancher
oh ok its posted now