Echo A Form

i want to make a order form but it is only for those who logged in. but i didnt show the form. i might do some mistake,can someone help me ?
here is the code

<?php
session_start();





if(isset($_SESSION['MM_Username'])) {


$MM_Username = $_SESSION['MM_Username'];
echo "<body>
<form name="form1" method="post" action="order_product_process.php">
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">Order Form:</p>
  <div align="center">
                                <table width="249" border="1" bgcolor="#000000">
                                  <tr>
                                                                <td width="54"><span class="style1">Name</span></td>
                                                                <td width="179"><input name="name" type="text" id="name" maxlength="30" value="<?php echo $MM_Username; ?>"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style4">Address</span></td>
                                                                <td><textarea name="address" id="address"></textarea> </td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style1">Phone</span></td>
                                                                <td><input name="phone" type="text" id="phone" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style9">IC Number </span></td>
                                                                <td><input name="ic" type="text" id="ic" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style8">Product Name </span></td>
                                                                <td><input name="product_name" type="text" id="product_name" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style1">Quantity</span></td>
                                                                <td>      <input name="quantity" type="text" id="quantity" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td>&nbsp;</td>
                                                                <td><input type="submit" name="Submit" value="Order">   <input name="Reset" type="reset" id="Reset" value="Reset"></td>
                                  </tr>
                                </table>
  </div>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>";



} else {
$MM_Username = '';
echo "why you dont register?";
}
?>
<style type="text/css">




body {background-attachment:fixed}
body {background-repeat:no-repeat}
-->
</style>
</head>




</html>

What are you seeing? Is the session definitely set, can you show the output from:


echo "<pre>";
print_r($_SESSION);
echo "</pre>";

You also need to escape all of the double quotes in the echo string. Could I suggest you break out of the PHP before the echo:


<?php
session_start(); 





if(isset($_SESSION['MM_Username'])) {


$MM_Username = $_SESSION['MM_Username'];
?>

<body>
<form name="form1" method="post" action="order_product_process.php">
  <p align="center" class="style10">&nbsp;</p>
...

Not that complicated, I think it’s better this way :


<?php
session_start();
if([B]![/B]isset($_SESSION['MM_Username'])) 
header("Location:loginpage.php"); // if not logged in redirects to login page
?>

<html>
<head>
<title>bla bla bla</title>

<style type="text/css">

body {background-attachment:fixed; background-repeat:no-repeat;}
-->
</style>

</head>

<body>
<form name="form1" method="post" action="order_product_process.php">
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">Order Form:</p>
  <div align="center">
                                <table width="249" border="1" bgcolor="#000000">
                                  <tr>
                                                                <td width="54"><span class="style1">Name</span></td>
                                                                <td width="179"><input name="name" type="text" id="name" maxlength="30" value="<?php echo $MM_Username; ?>"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style4">Address</span></td>
                                                                <td><textarea name="address" id="address"></textarea> </td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style1">Phone</span></td>
                                                                <td><input name="phone" type="text" id="phone" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style9">IC Number </span></td>
                                                                <td><input name="ic" type="text" id="ic" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style8">Product Name </span></td>
                                                                <td><input name="product_name" type="text" id="product_name" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style1">Quantity</span></td>
                                                                <td>      <input name="quantity" type="text" id="quantity" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td>&nbsp;</td>
                                                                <td><input type="submit" name="Submit" value="Order">   <input name="Reset" type="reset" id="Reset" value="Reset"></td>
                                  </tr>
                                </table>
  </div>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>
</html> 

It helps if you provide us an error to work with; though in this instance it’s pretty obvious where you’re going wrong. PHP shouldn’t be used to echo out HTML, at least not large amounts of it like in the above situation. You’re encasing the expression (which is the HTML code), inside double quotes, where other double quotes exist. This will cause you a parse error at run time. You’re also attempting to echo out a value inside of the expression that you are already outputting; which will not result in an error, it just won’t work.

You could either use the heredoc or nowdoc solutions (see the PHP Documentation for more information); the former being the better suited choice for this scenario because you’re wanting to output variable(s) inside of your HTML. This will mean that you don’t have to worry about escaping each and every quote inside of the expression. Or as a better, and more advised solution, you could drop in and out of your PHP code (which will also be the faster option as well):


<?php
session_start(); 

if(isset($_SESSION['MM_Username'])) {


$MM_Username = $_SESSION['MM_Username'];
?>
<body>
<form name="form1" method="post" action="order_product_process.php">
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">&nbsp;</p>
  <p align="center" class="style10">Order Form:</p>
  <div align="center">
                                <table width="249" border="1" bgcolor="#000000">
                                  <tr>
                                                                <td width="54"><span class="style1">Name</span></td>
                                                                <td width="179"><input name="name" type="text" id="name" maxlength="30" value="<?php echo $MM_Username; ?>"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style4">Address</span></td>
                                                                <td><textarea name="address" id="address"></textarea> </td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style1">Phone</span></td>
                                                                <td><input name="phone" type="text" id="phone" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style9">IC Number </span></td>
                                                                <td><input name="ic" type="text" id="ic" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style8">Product Name </span></td>
                                                                <td><input name="product_name" type="text" id="product_name" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td><span class="style1">Quantity</span></td>
                                                                <td>      <input name="quantity" type="text" id="quantity" maxlength="30"></td>
                                  </tr>
                                  <tr>
                                                                <td>&nbsp;</td>
                                                                <td><input type="submit" name="Submit" value="Order">   <input name="Reset" type="reset" id="Reset" value="Reset"></td>
                                  </tr>
                                </table>
  </div>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>

<?php
} else {
$MM_Username = '';
echo "why you dont register?";  
}
?>
<style type="text/css">




body {background-attachment:fixed}
body {background-repeat:no-repeat}
-->
</style>
</head>

</html>


Off topic: why are you outputting a form in the head of your HTML document?