registry problems

Ask about a PHP problem here.
Post Reply
doomrancher
Posts: 8
Joined: Thu Sep 05, 2013 4:01 am

registry problems

Post 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
<?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">           Username:</label>
				<input type="text" name="username" id="username" />
			</p>
			<p>
				<label for="password">            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>
				            <input type="submit" value="Register" />
			<p>
		</form>
		</center>
	</body>
</html>
protected.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>
init.inc.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");

?>
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]
Last edited by doomrancher on Fri Sep 20, 2013 5:22 am, edited 4 times in total.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: registry problems

Post 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.
doomrancher
Posts: 8
Joined: Thu Sep 05, 2013 4:01 am

Re: registry problems

Post by doomrancher »

ok i put up protected.php and init.inc.php as well
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: registry problems

Post 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++
doomrancher
Posts: 8
Joined: Thu Sep 05, 2013 4:01 am

Re: registry problems

Post by doomrancher »

i fixed the thing with the init.inc.php file but it's still not working
ScTech
Posts: 92
Joined: Sat Aug 24, 2013 8:40 pm

Re: registry problems

Post by ScTech »

You are missing a semicolon after your header redirect.
<?php while(!$succeed = try()); ?>
doomrancher
Posts: 8
Joined: Thu Sep 05, 2013 4:01 am

Re: registry problems

Post by doomrancher »

in which script?
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: registry problems

Post by Temor »

doomrancher wrote:in which script?
the same script.
doomrancher
Posts: 8
Joined: Thu Sep 05, 2013 4:01 am

Re: registry problems

Post by doomrancher »

i put in the semicolon but it still does the same thing
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: registry problems

Post 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:
error_reporting(E_ALL);
ini_set('display_errors', 1);
doomrancher
Posts: 8
Joined: Thu Sep 05, 2013 4:01 am

Re: registry problems

Post 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
ScTech
Posts: 92
Joined: Sat Aug 24, 2013 8:40 pm

Re: registry problems

Post by ScTech »

Post user.inc.php please.
<?php while(!$succeed = try()); ?>
doomrancher
Posts: 8
Joined: Thu Sep 05, 2013 4:01 am

Re: registry problems

Post by doomrancher »

i did
ScTech
Posts: 92
Joined: Sat Aug 24, 2013 8:40 pm

Re: registry problems

Post by ScTech »

You posted init.inc.php. user.inc.php contains all the functions to make it work.
<?php while(!$succeed = try()); ?>
doomrancher
Posts: 8
Joined: Thu Sep 05, 2013 4:01 am

Re: registry problems

Post by doomrancher »

oh ok its posted now
Post Reply