[UPHPU] Newbie needs help

dataw0lf digitalsuicide at gmail.com
Fri Jun 10 11:18:06 MDT 2005


John M wrote:

> Here is what I have in my php file now (anyone see any
> syntax problems there?)....
> 
> <?php 
> $name = $_REQUEST['name'];
> if (!isset($name))  {
> ?>
> <!-- No name has been provided, so we
>  prompt the user for one.       -->
> 
> <form action="<?=$_SERVER["PHP_SELF"]?>"
> method="post">
> Please enter your name: <input type="text" name="name"
> />
> <input type="submit" value="GO" />
> </form>
> 
> <?php } else  { ?>
> <p>Your name: <?=$name?></p>
> 	
> <p>This paragraph contains a <a
> href="newpage.php?name=<?=urlencode($name)?>">link</a>
> that passes the name variable on to the next
> document</p>
> 
> <?php } ?>

ICK!  I almost had a heart attack looking at this.  This is how I'd
implement it:

<?php
$name = $_REQUEST['name'];

if(!isset($name)) {
	echo('
		<form action="'.$_SERVER['PHP_SELF'].'" method ="post">
			Please enter your name: <input type="text" name="name" />
		<input type="submit" value="GO" />

		</form>
	');
} else {
	$getvar = urlencode($name);
	echo('
		<p>Your name:'.$name.'</p>
		<p>
			This paragraph contains a <a
href="newpage.php?name='.$getvar.'>link</a> that passes the name
variable to the next document
		</p>
	');
}

?>

Actually, I'd probably use heredocs, but that's just me, and I didn't
want to overly confuse you.

Embedding PHP into HTML is a bad way to design things (especially with
broken up braces, man, I didn't even know that was possible).


-- 
Joshua Simpson -- dataw0lf.org
Lead Network Administrator/Engineer Aero-Graphics Inc.
jsimpson at aero-graphics.com



More information about the UPHPU mailing list