0

So, it works like a charm when first going into the page. I write my feedback and press the submit button. Database gets all the info and nothing is wrong, but when i am doing a refresh it writes into the database, the same feedback form again, and depending how much i refresh, it always adds the same comment...`

        <div class="text_style" style="margin-bottom: -30px;">Leave a review:</div><input class="bejel" style="width: 380px; height: 140px; margin-bottom: 40px;" type="text" name="comment" placeholder="Leave a comment..."><br>

        <div class="text_style">Skins:</div>
        <div class="select"  style="margin-top: -35px;">
        <select name="skins">
        <option>Select your skin!</option>
        <option value="jax">Pax Jax</option>
        <option value="sivir">Pax Sivir</option>
        <option value="singed">Riot Singed</option>
        <option value="nasus">Riot Nasus</option>
        <option value="twisted">Pax Twisted Fate</option>
        <option value="ryze">Human Ryze</option>
        <option value="kayle">Silver Kayle</option>
        <option value="alistar">Black Alistar</option>
        </select></div>

        <div class="text_style" style="float: left;">Name:</div>
        <input class="bejel" type="text" name="name" placeholder="Name">

        <div class="text_style" style="float: left;">Email:</div>
        <input class="bejel" type="text" name="email" placeholder="E-mail">


        <input name="mod" type="submit" class="smb" value="" style="margin-bottom: 50px;">

        </form>                             
        </div>

    <?php
    $con = mysqli_connect("data for login");


    if (isset($_POST['mod']))
    {
       $SQL = "INSERT INTO feedback_comment (rate, comment, name, skin, email) VALUES ('5', '$_POST[comment]', '$_POST[name]', '$_POST[skin]', '$_POST[email]')";
        $result = mysqli_query($con, $SQL);
    }

    mysqli_close($con);
    ?>`
superphonic
  • 7,954
  • 6
  • 30
  • 63
LeviD77
  • 25
  • 3
  • 2
    see also [how to prevent form resubmission when page is refreshed via PHP](http://stackoverflow.com/questions/6320113/how-to-prevent-form-resubmission-when-page-is-refreshed-via-php) with answer - [Use the Post/Redirect/Get pattern](http://stackoverflow.com/a/6320124/689579) – Sean Jul 07 '14 at 22:23
  • 1
    I use `jquery` ajax post for this if possible, otherwise **PRG** is the way to go. – lodev09 Jul 07 '14 at 22:36

2 Answers2

2

Add unset($_POST); after the database submission code.

ssergei
  • 1,289
  • 9
  • 21
0

So, none of them worked really, but I decided to use a session to a submit page with header function and the submit button has no function... i cannot get this to go to submit.php with header location ONLY on button press. `

        <div class="text_style" style="margin-bottom: -30px;">Leave a review:</div><input class="bejel" style="width: 380px; height: 140px; margin-bottom: 40px;" type="text" name="comment" placeholder="Leave a comment..."><br>

        <div class="text_style">Skins:</div>
        <div class="select"  style="margin-top: -35px;">
        <select name="skins">
        <option>Select your skin!</option>
        <option value="jax">Pax Jax</option>
        <option value="sivir">Pax Sivir</option>
        <option value="singed">Riot Singed</option>
        <option value="nasus">Riot Nasus</option>
        <option value="twisted">Pax Twisted Fate</option>
        <option value="ryze">Human Ryze</option>
        <option value="kayle">Silver Kayle</option>
        <option value="alistar">Black Alistar</option>
        </select></div>

        <div class="text_style" style="float: left;">Name:</div>
        <input class="bejel" type="text" name="name" placeholder="Name">

        <div class="text_style" style="float: left;">Email:</div>
        <input class="bejel" type="text" name="email" placeholder="E-mail">


        <input name="mod" type="submit" class="smb" value="" style="margin-bottom: 50px;">

        </form>                             
        </div>

    <?php
        if (isset($_POST['mod'])) {

        $_SESSION['name'] = $_POST['name'];
        $_SESSION['rate'] = $_POST['rate'];
        $_SESSION['email'] = $_POST['email'];
        $_SESSION['skin'] = $_POST['skin'];
        $_SESSION['comment'] = $_POST['comment'];
        header('Location:submit.php');
       }`
LeviD77
  • 25
  • 3