Page 1 of 1
exit a php script but not the html
Posted: Wed Jun 18, 2003 1:53 pm
by hilophilo
how would I end the php script , but not the html. for example, when this line exits; it ignore anything below including the rest of the html lines.
example:
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
<td>
copyright 2002</td>
ignores:
it doesnt print out the word "copyright 2002" .
Re: exit a php script but not the html
Posted: Wed Jun 18, 2003 2:16 pm
by Drachlen
Code: Select all
<?php
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
}
?>
<table>
<td>copyright 2002</td>
</table>
Well, I tried a few different things and it never displayed, so i removed exit; and it displayed. You could always echo it inside of the php and then put exit below it if you need to..
Posted: Wed Jun 18, 2003 3:17 pm
by hilophilo
i trying removing the exit; before, but there was a problem and it just display a bunch if stuff from my db.
to be more define. here are lines.
if (!$searchtype || !$searchterm)
{
echo "You have not entered search details. Please go back and try again.";
}
echo "whatever";
echo "";
..
it starts to list everything i got in my database if i dont use exit;
Posted: Wed Jun 18, 2003 5:14 pm
by Galahad
Maybe you could put the other stuff in an else.
Posted: Thu Jun 19, 2003 5:31 am
by gurjit
what i usually do is refresh the page with a <meta> tag.
for example
Code: Select all
<?php
if ($num_rows == 0) {
?>
<meta http-equiv="refresh" content="0; url=forgotten_password.php?error=1">
<?php
exit;
} else {
do my query
}
?>
so in the body of the html you would have
you would have you html tables here
Code: Select all
<?php
if (isset($error)) {
echo "my error msg";
} else {
echo "my html";
}
?>
you would have your html footer here
this way you only change things in the body of your html.
hope this helps. the only disadvatage of this is that when you view it in dreamweaver you will see both the html for the error msg and the else.