jesushax Posted April 18, 2008 Share Posted April 18, 2008 hi below is my code could anyone tell me whats wrong? echoing $error doesnt seem to work cheers <?php include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php'); function ShowForm() { ?> <div id="content-left"> <form id="form" method="post" action="/includes/login.php" class="menu"> <table> <tr> <td>Username:</td><td><input name="txtUserName" type="text" size="20" /></td> </tr> <tr> <td>Password:</td><td><input name="txtPassword" type="password" size="20" /></td> </tr> <tr> <td colspan="2" style="text-align:right;"><input name="submit" type="submit" value="Login" /></td> </tr> <tr> <td colspan="2"> </td> </tr> <td colspan="2">Lost your password? <a href="/includes/lostpass.php">Click Here</a></td> </tr> </table> </form> </div> <div id="content-right"><span style="padding:30px 0 0 20px;"><?php echo $error; ?></span></div> <?php } switch(@$_GET["action"]) { Case "adminonly": $error = '<span style="font-weight:bold; color:#FF0000;">Error: You need to be a designer to access these pages.</span>'; echo "<h3>Client Log In</h3>"; ShowForm(); break; Case "noaccount": echo "<h3>Client Log In</h3>"; $error = '<span style="font-weight:bold; color:#FF0000;">Error: You need to be a designer or a client to access these pages.</span>'; ShowForm(); break; Case "invalid": echo "<h3>Client Log In</h3>"; $error = '<span style="font-weight:bold; color:#FF0000;">Error: Either your username or password are incorrect.</span>'; ShowForm(); break; Case "sent": echo "<h3>Client Log In</h3>"; $error = '<span style="font-weight:bold; color:#FF0000;">Error: Your Password has been sent to the email address provided</span>'; ShowForm(); break; default: echo "<h3>Client Log In</h3>"; ShowForm(); break; } include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/101701-echoing-variable-problem/ Share on other sites More sharing options...
jonsjava Posted April 18, 2008 Share Posted April 18, 2008 You've gotta pass the error to ShowForm <?php $error = "this is the error"; include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php'); function ShowForm($error) { ?> <div id="content-left"> <form id="form" method="post" action="/includes/login.php" class="menu"> <table> <tr> <td>Username:</td><td><input name="txtUserName" type="text" size="20" /></td> </tr> <tr> <td>Password:</td><td><input name="txtPassword" type="password" size="20" /></td> </tr> <tr> <td colspan="2" style="text-align:right;"><input name="submit" type="submit" value="Login" /></td> </tr> <tr> <td colspan="2"> </td> </tr> <td colspan="2">Lost your password? <a href="/includes/lostpass.php">Click Here</a></td> </tr> </table> </form> </div> <div id="content-right"><span style="padding:30px 0 0 20px;"><?php echo $error; ?></span></div> <?php } switch(@$_GET["action"]) { Case "adminonly": $error = '<span style="font-weight:bold; color:#FF0000;">Error: You need to be a designer to access these pages.</span>'; echo "<h3>Client Log In</h3>"; ShowForm(); break; Case "noaccount": echo "<h3>Client Log In</h3>"; $error = '<span style="font-weight:bold; color:#FF0000;">Error: You need to be a designer or a client to access these pages.</span>'; ShowForm(); break; Case "invalid": echo "<h3>Client Log In</h3>"; $error = '<span style="font-weight:bold; color:#FF0000;">Error: Either your username or password are incorrect.</span>'; ShowForm(); break; Case "sent": echo "<h3>Client Log In</h3>"; $error = '<span style="font-weight:bold; color:#FF0000;">Error: Your Password has been sent to the email address provided</span>'; ShowForm(); break; default: echo "<h3>Client Log In</h3>"; ShowForm(); break; } include($_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/101701-echoing-variable-problem/#findComment-520304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.