0

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
  • 1
    Could you share code snippet? Commented Oct 9, 2014 at 12:21

2 Answers 2

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!";
 }
Sign up to request clarification or add additional context in comments.

3 Comments

is the text gets printed in your page or in a text field??
Looks like that was it. Commenting it out removed it.
use the condition inside a submit event or so, it won't print unless its executed... SEE SOLUTION...
0

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'];}?>"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.