1

How exactly is IF EXIST function used in MySQL? Alternatively, how can one make sure that the values previously filled into the input fields are cleared completely so that they are not re-posted once the page is reloaded?

This is a slice of my code

<?php
function testInput($data){
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

if($_SERVER['REQUEST_METHOD']=='POST'){
    $user = testInput($_POST['userName']);
    $fName = testInput($_POST['fName']);
    $lName = testInput($_POST['lName']);
    $fPass = md5(testInput($_POST['fPass']));
    $rPass = md5(testInput($_POST['rPass']));
    $gender = testInput($_POST['gender']);
}               
?>

I want to make sure that the value of my variables='' every time I refresh my page.

2
  • Make a header('Location: ...'); redirect to the same page. Commented Jul 8, 2014 at 16:25
  • You set the form values in HTML. Commented Jul 8, 2014 at 17:15

1 Answer 1

2

What you are looking for is to prevent repost or backbutton repost

there are many ways to do this

  • use of session cookie and only allow that session to post once in php

  • using ajax to post to self or a new page in php so refreshing or backing will prevent repost

  • iframe the form will also do the trick

  • Post + Redirect to self

Sign up to request clarification or add additional context in comments.

2 Comments

exactly, I am trying to prevent the repost...I would go with the first option as I am somewhat unfamiliar with the other options...Thank you. W
@user3386046 Most common approach are use of ajax api.jquery.com/jquery.post or just redirect to same page (which will clear the post data)

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.