Code will not allow html to show.

Ask about a PHP problem here.
Post Reply
DonVito186
Posts: 5
Joined: Mon Jun 06, 2011 3:55 pm

Code will not allow html to show.

Post by DonVito186 »

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:
<?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>
User avatar
element
Posts: 8
Joined: Mon May 16, 2011 7:20 pm
Location: Germany

Re: Code will not allow html to show.

Post by element »

In line 15 you have a : instead of ;
and in line 25 is a ) to much...
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Code will not allow html to show.

Post by jacek »

DonVito186 wrote: So all i get is a blank page
That suggests you made a syntax error somewhere and do not have php set up to tell you about it, so it just dies. If you have access to the php.ini file you can set error_reporting = E_ALL and display_errors = On for more info ... http://www.youtube.com/watch?v=4OH0b-x96Zo
Image
DonVito186
Posts: 5
Joined: Mon Jun 06, 2011 3:55 pm

Re: Code will not allow html to show.

Post by DonVito186 »

I fixed the miss-spelling that element pointed out. I also edited the ini file to display errors, and it doesnt say anything. I still get a blank screen.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Code will not allow html to show.

Post by jacek »

Did you restart Apache after editing php.ini ?
Image
DonVito186
Posts: 5
Joined: Mon Jun 06, 2011 3:55 pm

Re: Code will not allow html to show.

Post by DonVito186 »

I am not using Apache, but rather IIS7. And yes i did restart it and still nothing.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Code will not allow html to show.

Post by jacek »

Can you post the full code as it is now ?

Also does your php set up work ? you could try a test file like
<?php

echo 'test';

?>
to check this.

Sorry for the patronising questions, I have to ask :lol:
Image
DonVito186
Posts: 5
Joined: Mon Jun 06, 2011 3:55 pm

Re: Code will not allow html to show.

Post by DonVito186 »

My PHP works, i've been working on other pages for my website other than the login/register. Below is the code as is now.
<?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>
User avatar
element
Posts: 8
Joined: Mon May 16, 2011 7:20 pm
Location: Germany

Re: Code will not allow html to show.

Post by element »

Line 25. Syntax error
remove 1 ) :lol:
$_SESSION['username'] = htmlentities($_POST['username']);
DonVito186
Posts: 5
Joined: Mon Jun 06, 2011 3:55 pm

Re: Code will not allow html to show.

Post by DonVito186 »

element wrote:Line 25. Syntax error
remove 1 ) :lol:
$_SESSION['username'] = htmlentities($_POST['username']);
That line was in the tutorial and it worked for him, but now its working for me. Thank you so very much!
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Code will not allow html to show.

Post by jacek »

DonVito186 wrote:That line was in the tutorial and it worked for him, but now its working for me. Thank you so very much!
I had it with one ) ;)

Also php should have told you about this error :? Something is stopping your errors from being displayed. You will find it very hard to debug / develop with hidden errors.
Image
Post Reply