内嵌打印PHP错误,而不是擦除整个页面 [英] Printing a PHP error inline instead of erasing the entire page
本文介绍了内嵌打印PHP错误,而不是擦除整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让PHP打印内嵌错误,而不是改变整个页面?
How can I make PHP print an error inline instead of changing the entire page?
我希望它定位 #errors
并填写,而不是更改所有内容。
I'd like it to target #errors
and fill that instead of changing everything.
我目前使用的代码是 die(用户名或密码不正确);
我对PHP很新奇,如果这是一件很容易的事情,那么很抱歉。
I'm very new to PHP so sorry if this is a pretty easy thing to do.
推荐答案
将错误放在您执行逻辑的变量中,并在#errors中打印其内容。例如:
Put the error in a variable where you do your logic and print its contents in #errors. For example:
if (username_is_incorrect()) $error = 'Incorrect username or password.';
而在HTML
<?php if (isset($error)):?><div id="errors"><?=$error?></div><?php endif;?>
这篇关于内嵌打印PHP错误,而不是擦除整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文