[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3900
  • Last Modified:

PHP center echo statement

How do I center an echo statement using php. Here is my code so far:

<html>
<head />
<body>
<p align="center">
<img src="websitehere/images/about/CG210.png" width="321" height="188">

</p>
<p align="center"><font size="4">Digital Plan Room</font></p>

<form action="login2.php" method=POST>
&nbsp;<table border="0" width="100%" id="table1">
      <tr>
            <td>&nbsp;</td>
            <td align="center">Username: <input type=text name=user></td>
            <td>&nbsp;</td>
      </tr>
      <tr>
            <td>&nbsp;</td>
            <td align="center">Password: <input type=password name=pass></td>
            <td>&nbsp;</td>
      </tr>
      <tr>
            <td colspan="3" align="center">
<input type=submit value="Login"></td>
      </tr>
</table>
<p>&nbsp;</p>
<p>
<p>
</form>



<?php

$user=$_POST['user'];
$pass=$_POST['pass'];

$link="<a href=\"some html link is here\">View Plans</a>";


if(($user=="username") && ($pass=="password")) echo $link; <------------------------------What I am trying to center

else echo "Please Login";  <---------------------------------------------------What I am trying to center

?>

</body>
</html>
0
bcmeyer1983
Asked:
bcmeyer1983
  • 3
1 Solution
 
glcumminsCommented:
PHP knows nothing about centering or other design ideas. You will need to enclose your text in HTML and CSS to perform the centering for you:

else echo '<div style="text-align: center;">Please Login</div>";
0
 
glcumminsCommented:
Correcting quotes:

 else echo '<div style="text-align: center;">Please Login</div>';
0
 
ll_jaxnCommented:
Actually just put <center></center> around your Please Login

and you might actually want to use your table!!!

   <tr>
            <td>&nbsp;</td>
            <td align="center">Username: </td>
            <td><input type=text name=user></td>
      </tr>
      <tr>
            <td>&nbsp;</td>
            <td align="center">Password: </td>
            <td><input type=password name=pass></td>
      </tr>
0
 
glcumminsCommented:
ll_jaxn: The center tag may still work in some browsers, but it is deprecated as of HTML 4.01 (See http://www.w3schools.com/tags/tag_center.asp). CSS styles are to be preferred over the use of <center>.
0
 
gemdeals395Commented:
Yup, The <center> tag is deprecated. He may not want to alter is html above for a reason. So on your PHP just add the centering table, div or whater you want right to the PHP:

<?php

$user=$_POST['user'];
$pass=$_POST['pass'];

$link="<a href=\"some html link is here\">View Plans</a>";


if(($user=="username") && ($pass=="password")) echo('<table width="100%"><tr><td align="center">'."$link".'</td></tr></table>'); //<------------------------------What I am trying to center

else echo('<table width="100%"><tr><td align="center">Please Login</td></tr></table>');  //<---------------------------------------------------What I am trying to center

?>
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now