exit a php script but not the html

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
hilophilo
Forum Newbie
Posts: 2
Joined: Wed Jun 18, 2003 1:53 pm

exit a php script but not the html

Post 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" .
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Re: exit a php script but not the html

Post 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..
hilophilo
Forum Newbie
Posts: 2
Joined: Wed Jun 18, 2003 1:53 pm

Post 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;
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post by Galahad »

Maybe you could put the other stuff in an else.
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post 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.
Post Reply