php clear text printed to webpage

﹥>﹥吖頭↗ 提交于 2019-12-13 04:57:49

问题


I have a html/php script which prints a text string directly to the page. However when I refresh the page that text is still there. I've googled this and check this forum too and tried various suggestions e.g.

<input autocomplete="off">

and

<body onload="document.FormName.reset();">

etc. None of them work.

The php code that prints the string is (if regex matches serial number then execute command else print error string):

if (preg_match($snregex, $sn, $matches)) {
  <command>
} else {
  echo "Invalid SN. Please re-enter!";
}

Should I print the string using a different way that can be cleared on refresh?


回答1:


if (preg_match($snregex, $sn, $matches)) {
 <command>
} else {
  //echo "Invalid SN. Please re-enter!";
 }

try commenting the echo and check if the text is still there.

if not, every time the else loop gets executed and prints the statement.

solution:

if(isset($_POST['submit']) && (preg_match($snregex, $sn, $matches))
{
 <command>
} else {
  echo "Invalid SN. Please re-enter!";
 }



回答2:


Is it printing out from a session or post var that's not getting cleared ? is the input field something like

input value="<?php if(isset($_POST['serial_number'])){echo S_POST['serial_number'];}?>"


来源:https://stackoverflow.com/questions/26278179/php-clear-text-printed-to-webpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!