If I have code such as:
<html>
...
<?php
....
die();
?>
....
</html>开发者_高级运维;
then the entire page execution stops, and the final html does not get shown. is there a way to only leave the php within the enclosing php tags?
I guess this is based on same condition, otherwise it wouldn't make sense.
<html>
...
<?php
....
if (! condition) { //skip if not needed
...
}
?>
....
</html>
Don't ever call die()
inside an HTML script. If you are calling die()
as part of mysql_query()
error checking, for example, you should instead wrap the call in an if()
statement. This doesn't only apply to MySQL, of course. You can use this in place of any instance where you would call die()
.
// Instead of this...
$result = mysql_query() or die();
// Do this...
$result = mysql_query(...);
if (!$result) {
$errorstring = "an error occurred producing your data";
}
It is generally considered bad practice to include a lot of application logic within the HTML. Instead do these things at the top of the script and store the output in variables for reuse later.
You can't die()
and expect execution will continue. That is illogical and impossible
what you should do is have an external php script and iframe it into the page, or use jquery to ajax it in. Then if it dies nothing will be displayed in the iframe, or div (if you use jquery), but you can still die
精彩评论