Page 1 of 1

PHP PAGE CODE Q

Posted: Fri Dec 27, 2013 6:34 am
by vivi007
my php web page keep displaying blank page, here is my php page:

Code: Select all

<html >
<head>
    <title>Registration Result</title>
</head>
<body>
<h1>Thank you for registering with us!</h1>
<?php
$firstname=$_POST['firstname']; 
echo"Thank you, <b>$name</b>.<b>You enter the following details:<br/>"; 
$gender=$_POST['gender']; 
echo"1.<b>Gender.<b>$gender<br/>"; 
$userid=$_POST['userid']; 
echo"2.<b>Userid.<b>$userid<br/>"; 
$password=$_POST['password'];
echo"3.<b>Password.<b>$password<br/>";
$date=$_POST['date'];
$month=$_POST['month'];
$comments=$_POST['comments'];
echo"3.<b>Date of Birth.<b>$date/$month/$comments<br/>";


if(!empty($_POST['firstname'])){
   $firstname=$_POST['firstname'];
}   
else if{
   $firstname=null;
   echo"<p>You didn't enter your name!</p>";
}
if(!empty($_POST['gender'])){
   $gemder=$_POST['gender'];
}   
else if{
   $gender=null;
   echo"<p>You didn't enter your gender!</p>";
}
if(!empty($_POST['userid'])){
   $userid=$_POST['userid'];
}   
else if{
   $userid=null;
   echo"<p>You didn't enter your userid!</p>";
}
if(!empty($_POST['password'])){
   $password=$_POST['password'];
}   
else if{
   $password=null;
   echo"<p>You didn't enter your password!</p>";
}
if(!empty($_POST['date'])){
   $date=$_POST['date'];
}   
else if{
   $date=null;
   echo"<p>You didn't enter the date!</p>";
}
if(!empty($_POST['month'])){
   $month=$_POST['month'];
}   
else if{
   $month=null;
   echo"<p>You didn't enter the month!</p>";
}
if(!empty($_POST['comments'])){
   $commments=$_POST['comments'];
}   
else if{
   $comments=null;
   echo"<p>You didn't enter the year!</p>";
}
if($userid="johntan"&&
   $password="niceday!";){
   header("Location:NEW4.html")
}
else if{
echo"<p>Login is not successful, please try again</p>";
}
?>

</body>
</html>
i use readyspace to do website, thanks for help.

Re: PHP PAGE CODE Q

Posted: Sat Dec 28, 2013 9:53 pm
by califdon
First, does the file that contains that code have a filetype of .php? It must have.

Then, you are using the function header(....) almost at the bottom of your code. That won't work. The header() function can only be used BEFORE anything has been sent to the browser--even a blank line! Once your PHP script has sent absolutely anything to the browser, it can not send a header() function. See http://us3.php.net/manual/en/function.header.php. There are several ways to do what you want to do: instead of using header(....), you can send Javascript code such as:

Code: Select all

echo "<script type='text/javascript'>document.location='NEW4.html';</script>";
or you could rewrite this code to BEGIN (even before the <html> tag!) with the test for username and password:

Code: Select all

if($userid="johntan"&&
   $password="niceday!";){
   header("Location:NEW4.html")
}
For a practical application, you should definitely not use data from a user directly in your application (such as saving it in a database) without "cleansing" the data to avoid "SQL injection"! PHP has several ways to reject input that could contain harmful data, such as SQL commands! Read http://www.acunetix.com/websitesecurity/sql-injection/.