0
$message .= "<tr><th>First Name</th><td>".$_POST['fname']."</td><th>Last Name</th><td>".$_POST['lname']."</td></tr>";
$message .= "<tr><th>Email</th><td>".$_POST['email']."</td><th>Telephone number</th><td>".$_POST['telno']."</td></tr>";
$message .= "<tr><th>Company Name</th><td>".$_POST['cname']."</td><th>Mobile number</th><td>".$_POST['mobileno']."</td></tr>";
$message .= "<tr><th>Address</th><td>".$_POST['address']."</td><th>City</th><td>".$_POST['city']."</td></tr>";
$message .= "<tr><th>Zip Code</th><td>".$_POST['zipcode']."</td><th>State</th><td>".$_POST['state']."</td></tr>";
$message .= "<tr><th>Country</th><td>".$_POST['country']."</td><th>Fax</th><td>".($_POST['fax'] == '' ? 'NA' : $_POST['fax'])."</td></tr>";
$message .= "<table>";
  • Just want to write HTML and PHP separately how to write?

  • Please show in different way to write PHP and HTML file?

  • I want to write $message ie variable only once in the program?

Also show how to write this code HTML and PHP in same page of file.php but splitting HTML and PHP

Diwakar yadav
  • 39
  • 2
  • 8
  • 1
    You can just exit PHP-mode, `?>` and use HTML as you want - then where you need PHP variables, open a PHP tag, do what needs to be done - and you can then go out again. Example: `....` and so on. – Qirel Feb 03 '17 at 11:18
  • please do it for first line First Name? – Diwakar yadav Feb 03 '17 at 11:20
  • I sort of already did... ;-) The start of it, anyway. See http://stackoverflow.com/a/18140338/4535200 – Qirel Feb 03 '17 at 11:22
  • Splitting PHP and raw HTML sections only makes sense for direct output. Not for assignment to a variable. What you rather want to investigate are HEREDOC strings to simplify that pile of code. (And context escaping, for that matter.) – mario Feb 03 '17 at 11:24
  • $message .= "Plastic Coated Paper".($_POST['plastic_coated_paper'] == 'Select Paper' ? 'NA' : $_POST['plastic_coated_paper']). "100% Pure Plastic".($_POST['pure_plastic'] == 'Select Plastic' ? 'NA' : $_POST['pure_plastic']).""; i want to remove only dot from .$_POST['']== '' and write in different way .....any idea – Diwakar yadav Feb 03 '17 at 12:01
  • double quotes in php process php variable too, so you dont need to concatenate $_POST with string, just write it within the string and it will work :) `$message .= "First Name$_POST['fname']Last Name$_POST['lname']";` – Mohammad Mudassir Feb 03 '17 at 12:05
  • If you want to clean your code further use can use `sprintf()` http://php.net/manual/en/function.sprintf.php – Mohammad Mudassir Feb 03 '17 at 12:07
  • can i echo the $_POST or write it with – Diwakar yadav Feb 03 '17 at 12:09

2 Answers2

0

double quotes in php process php variable too, so you dont need to concatenate $_POST with string, just write it within the string and it will work :)

$message .= "<tr><th>First Name</th><td>$_POST['fname']</td><th>Last Name</th><td>$_POST['lname']</td></tr>";

If you want to clean your code further use can use sprintf() php.net/manual/en/function.sprintf.php

0

You can use simple HTML structure in your php file.

<table>
    <tr>
        <th>First Name</th> 
        <td> <?php $_POST['fname']; ?> </td>
        <th>Last Name</th> 
        <td> <?php $_POST['lname']; ?></td>
    </tr>
    <tr>
        <th>Email</th> 
        <td> <?php $_POST['email']; ?> </td>
        <th>Telephone number</th>
        <td> <?php $_POST['telno']; ?></td>
    </tr>
    <tr>
        <th>Company Name</th> 
        <td><?php $_POST['cname']; ?></td>
        <th>Mobile number</th>
        <td><?php $_POST['mobileno']; ?></td>
    </tr>
    <tr>
        <th>Address</th>
        <td><?php $_POST['address']; ?></td>
        <th>City</th>
        <td><?php $_POST['city']; ?></td>
    </tr>
    <tr>
        <th>Zip Code</th>
        <td><?php $_POST['zipcode']; ?></td>
        <th>State</th>
        <td><?php $_POST['state']; ?></td>
    </tr>
    <tr>
        <th>Country</th>
        <td><?php $_POST['country']; ?></td>
        <th>Fax</th>
        <td><?php ($_POST['fax'] == '' ? 'NA' : $_POST['fax']); ?</td>
    </tr>
</table>

If you want to put all this code into a variable (f.ex. $message), as a variant, you can do the next. Put all code into one php file (f.ex. table.php) and in the other file (f.ex. index.php) include it by writing such code:

<?php
    $message = require_once __DIR__.DIRECTORY_SEPARATOR. 'table.php';
    echo $message;
?>