Log in

View Full Version : Mysteriously Vanishing Footer



kuau
05-16-2008, 03:32 AM
This code excerpt causes my footer to show up only when there is an error. I think it has something to do with "exit." Anyone know how to make the footer show all the time? Thanks! erin


if ($myrow[cal_email] == ""){
$error = "<p>NO RECORD WAS FOUND.</p>";
if ($error != ""){ echo "<font color=990000>$error</font>"; }
} else {
mail("$email", "Your Login Info ", "Blah blah");
print "<p>YOUR PASSWORD WAS MAILED.</p>";
exit; }
}
?>
</div>
<div id="footer"><? include('footer.php'); ?></div>

jerry_linseed
05-16-2008, 03:54 AM
HI Erin,

I don't think you need an 'exit' there, I've never used that (when I want to get out of a conditional or a loop... I've used 'break' before).

I noticed theres an extra }, is that for some code above that?

This is how I'd handle that part:


<?php

if ($myrow[cal_email] == "")
{
$error = "<p>NO RECORD WAS FOUND.</p>";
echo "<font color=990000>$error</font>";
}
else
{
mail("$email", "Your Login Info ", "Blah blah");
echo "<p>YOUR PASSWORD WAS MAILED.</p>";
}

?>

</div>

<div id="footer"><? include('footer.php'); ?></div>

I removed the if($error!="") because it was in a section which had just set error to something - so it would always be true in that code (to avoid that - you need a '}'after the $error= statement). I consolidated that and it should work fine.

Mainly though, the problem with what you asked about was 'exit'. That stops the whole script! It only ran when there was no error, since the other branch (error) skipped the part with 'exit'. Don't 'exit'!

Hope that helps.
-Jerry

kuau
05-16-2008, 04:10 AM
Dear Jerry: Thank you! Did I mess it up? because it still doesn't show. Here's more of the code. It is driving me nuts:


<form action=/php/password.php method=post>
<input type=hidden name=action value=doit>
<b>Email:</b> <input type=text name=email size=35>
<input type=submit value=SEARCH>
</form>
<?
if ($action == "doit")
{
require "mysql_options.php";
require "my_functions.php";
$mydatabase = new MySQL_options;
$mydatabase->init();
$sql = "SELECT * FROM webcal_user WHERE cal_email='$email' ";
$data = $mydatabase->select($sql);
$num = count(data);
$myrow = $data[0];
if ($myrow[cal_email] == "")
{
$error = "<p>NO RECORD WAS FOUND IN THE DATABASE FOR:</p><p><b>$email</b></p><p>Please try again.</p>";
echo "<font color=990000>$error</font>";
} else {
mail("$email", "Your Calendar Maui Login Info ", "Aloha $myrow[cal_firstname],\n\n Your username is: $myrow[cal_login] \n\n Your password is: $myrow[cal_passwd] \n\n Please go to http://www.calendarmaui.com/ to log in. ", "From: Calendar Maui<info@calendarmaui.com>\r\n");
echo "<p>YOUR USERNAME AND PASSWORD WERE MAILED TO:</p><p><b>$email</b></p><p>Please check your email.</p>";
}} ?>
</div>
<div id="footer"><? include_once('footer.php'); ?></div>

Rockonmetal
05-17-2008, 12:02 AM
if you are using a variable in the middle of a string do this:

"bla bla bla" . $variable . "rest of string";
That is all I saw but otherwise it looks ok...

kuau
05-17-2008, 12:46 AM
Thanks, Rockon: It's working!! Thanks a million. erin :) PS. is the \n\n part of the string or the php?

Rockonmetal
05-17-2008, 12:17 PM
Um... err... I don't know... I just use <br /> tags. I don't think so... Uh One other thing... Next time please, pretty please? use the code boxes... They are really helpful and make it easier on our eyes... Thanks!
I'm glad I could help!

kuau
05-18-2008, 09:00 PM
Dear Rockon: I went back and put the code tags just for you. Thanks for your help!

erin :)