Code will not allow html to show.
Posted: Mon Jun 06, 2011 4:00 pm
I followed a tutorial on youtube from betterphp about using MySQL and PHP to create a login and register system for a web site. I followed as the tutorial showed, up to part 3. The problem is when i have the php/sql code in the file, it wont let the html code show up on the screen. So all i get is a blank page. But when i remove the php code the html code shows up and i see what i want to. Below is my script used:
[syntax=php]<?php
include('core/init.inc.php');
if (isset($_POST['username'], $_POST['password'], $_POST['repeat_password'])){
if (empty($_POST['username'])){
$error[] = '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();
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>HELLO</title>
</head>
<body><p>
<?php
?>
</p>
<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>
<lablefor="repeat_password">Repeat Password:</label>
<input type="password" name="repeat_password" id="repeat_password" /></p>
<p>
<input type="submit" value="Register" />
</p>
</form>
</body>
</html>
[/syntax]
[syntax=php]<?php
include('core/init.inc.php');
if (isset($_POST['username'], $_POST['password'], $_POST['repeat_password'])){
if (empty($_POST['username'])){
$error[] = '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();
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>HELLO</title>
</head>
<body><p>
<?php
?>
</p>
<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>
<lablefor="repeat_password">Repeat Password:</label>
<input type="password" name="repeat_password" id="repeat_password" /></p>
<p>
<input type="submit" value="Register" />
</p>
</form>
</body>
</html>
[/syntax]