SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Echo A Form

  1. #1
    SitePoint Member
    Join Date
    Nov 2012
    Posts
    9
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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

    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>

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2012
    Location
    Scarborough, North Yorkshire, United Kingdom
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are you seeing? Is the session definitely set, can you show the output from:

    PHP Code:
    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 Code:
    <?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>
    ...
    Richard
    Resell SSL Certificates - API / WHMCS / HostBill / ClientExec
    ServerTastic - RapidSSL, Geotrust, Thawte, Symantec, SmarterTools and more

  3. #3
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not that complicated, I think it's better this way :
    Code:
    <?php
    session_start();
    if(!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>
    Last edited by tentim; Nov 13, 2012 at 11:42. Reason: Added the session_start bit

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    124
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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 Code:
    <?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?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •