Welcome Guest, Not a member yet? Register   Sign In
How Can I Destroy User Data After Insertion ?
#1

[eluser]Zeeshan Rasool[/eluser]
Hi all, here is a problem im facing.

Problem is , when i create a new user and click submit button the CREATE_USER_DB function executes and new user has been inserted. But when i refresh the page by pressing F5 or else an other user data is inserted in DB with same record values
How can i destroy userdata or $_POST data so it can be stopped?

Very Thnx in Advance.
#2

[eluser]sanct_arvin[/eluser]
redirect it to another page.


Code:
$query = $this->db->insert('users', $_POST);
        $user_id = $this->db->insert_id();

            $data['msg'] = 'Successfully Registered: '.$_POST['lname'].', '.$_POST['fname'];
            $data['title'] = 'Successful'; //title of the page
            $data['sec'] = 5; //secs before redirection
            $data['heading'] ='Successfully Registered'; // heading :D
            $data['url'] = base_url().'index.php/user/nextlocation'; //your next location
            $_SESSION['user_id']= $user_id; //set session variable to check if he/she is logged in

        $this->load->view('prompt.php', $data);

create a redirection page


in your prompt.php
Code:
<html>
<head>
    <title><?=$title?></title>
    
    <meta http-equiv="refresh" content="<?=$sec?>;url=<?=$url?>">

<style>
    td, th, pre, body, input, textarea, span, div, p{
        font-family: Verdana, Arial;
        font-size: 11px;
        vertical-align:top;
    }
    .main{
        display: inline;
        width: 95%;
    }
    .right{ width:100%}
    .left{ padding-left: 10px; padding-right: 10px;}

    .msg{border:1px dashed fff }
    
    
</style>
</head>
<body>
<?=$sec?>
<?=$url?>
    
    <h3>&lt;?=$heading?&gt;</h3>    
    
    <div class='msg'>
        &lt;?=$msg?&gt;
    </div>
    
&lt;/body&gt;
&lt;/html&gt;

i use it every time i don't want a duplicate data Big Grin
you can use it in every pages that would insert data.
kudos!

regards
- sanct_arvin
#3

[eluser]Sumon[/eluser]
You can also use
Code:
foreach($_POST as $Key => $Value)
  {
     $POST[$Key] = "";
     unset($POST[$Key]);
  }
After this when your page reloaded all fields will be empty. So empty data can't register itself.

Hope it helps you
#4

[eluser]Grahack[/eluser]
Strange, I thought that this F5 thing was browser related. No matter what happens server-side, our browsers often remember what they "posted", so resetting the $_POST array seems to me useless.
#5

[eluser]Sumon[/eluser]
Ops... sorry for my post. You are right. It's completely browser dependent. So it might better to redirect into another function().
#6

[eluser]Zeeshan Rasool[/eluser]
Thnx yaar! so what shud me do now?
#7

[eluser]sanct_arvin[/eluser]
redirect it to another page after your insert

use redirect() function
#8

[eluser]Zeeshan Rasool[/eluser]
Got it ! thank you all
#9

[eluser]Colin Williams[/eluser]
It is generally good practice to redirect "successful" form posts (though doing a meta redirect from HTML is not the best thing, when you can just initiate a new HTTP request from PHP), and use Session variables to pass along information, like messages, or even original $_POST data. Some frameworks do this.... has me thinking... Gah! So many good ideas for CI libraries!
#10

[eluser]gh0st[/eluser]
The way I used to do it was;

Form -> processSomething.php -> Result

I call it a "processing file" and it does the work and redirects once its finished so that if the user press back or press F5 it won't cache the result.

Although you still need to do checks to ensure that the data in processSomething.php is valid and accurate (perhaps delaying how many times someone can press `submit` on a form, etc) you can stop this issue.

But I'm not sure whether using a redirect as shown above is firstly MVC, and secondly correct.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB