PHP Newbie Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ryan1111
Forum Newbie
Posts: 2
Joined: Mon Mar 21, 2005 8:14 pm

PHP Newbie Question

Post by ryan1111 »

I'm creating my first PHP webpage. It's a login page. If the user enters the wrong information, of course, I want to let them know. All of the examples I see use echo(). However, I don't want the error message to appear in the upper left corner of the window. I want it to appear at a specific place on the page. How on earth do I do this?

Thanks!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

echo out the html up to that specific point, or use a template-esque system of content display.

Code: Select all

<?php

$template =<<<STOP
<html>
  <head>
    <title>{TITLE}</title>
  </head>
  <body>
    <div style=&quote;text-align:right; border: 2px red solid; background-color: yellow; color: blue; padding: 10px 10px 10px 10px; font-weight: bold;&quote;>{ERROR_DATA}</div>
  </body>
</html>
STOP;

$error = 'Hi. I\'m an error.';
$title = 'I\'m a title';

$find = array('{TITLE}', '{ERROR_DATA}');
$rep = array($title, $error);

$output = str_replace($find, $rep, $template);

echo $output;

?>

Code: Select all

<html>
  <head>
    <title>I'm a title</title>
  </head>
  <body>
    <div style=&quote;text-align:right; border: 2px red solid; background-color: yellow; color: blue; padding: 10px 10px 10px 10px; font-weight: bold;&quote;>Hi. I'm an error.</div>
  </body>
</html>
ryan1111
Forum Newbie
Posts: 2
Joined: Mon Mar 21, 2005 8:14 pm

Post by ryan1111 »

Thanks! You pointed me in the right direction. :D
Post Reply