error PHP Tutorial: Reg & Login (User Act System) [part 4]

Ask about a PHP problem here.
Post Reply
cohenj
Posts: 1
Joined: Tue Jul 02, 2013 5:50 pm

error PHP Tutorial: Reg & Login (User Act System) [part 4]

Post by cohenj »

Hello Jacek,

I am following your User Account System Youtube tutorials and I am stuck when I am trying to complete Part 04.

Whenever I run my register.php file, I get an error in Firefox that says: "The character encoding of the HTML document was not declared..."

Now I've come to realize that when I have my PHP code before the HTML code, I get this error. If I remove the PHP code, my page appears. Do you have any suggestions on how I can get my page displayed but also have the PHP code there?

My code is:

[syntax=php]<? php

include('core/init.inc.php');
$errors = array();

if(isset($_POST['fullname'], $_POST['email'])){

if(empty($_POST['fullname'])){
$errors[] = 'The full name field cannot be empty.';
}

if(empty($_POST['email'])){
$errors[] = 'The email field cannot be empty.';
}

if(user_exists($_POST['email'])){
$errors[] = 'The email you entered is already taken.';
}
if (empty($errors)){
add_user($_POST['fullname'], $_POST['email']);
$_SESSION['fullname'] = htmlentities($_POST['fullname']);
header('Location: index.php');
die();
}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta content="utf-8" http-equiv="encoding" />
<title>TEST</title>
</head>
<body>
<section>
<form action="" method="post">
<h1> Register</h1>
<div>
<?php

if(empty($errors) === false){
?>
<ul>
<?php
foreach ($errors as $error){
echo "<li>{$error}</li>";}
?>
</ul>
<?php
}
?>
</div>
<p>
<label for="fullname">Your Full Name</label>
<input id="fullname" name="fullname" required="required" type="text"/>
</p>
<p>
<label for="email"> Your email</label>
<input id="email" name="email" required="required" type="email" />
</p>

<p>
input type="submit" value="Sign up"/>
</p>

</form>
</section>
</body>
</html>[/syntax]

Please help!

Thank you,

JC
Last edited by Helx on Tue Jul 02, 2013 6:32 pm, edited 1 time in total.
Reason: Code tags
Post Reply