0

i have code like this..

how to redirect after insert data will redirect to domain www.mydomain.com/go/[$no]

sample redirect : www.mydomain.com/go/4656566665

if ($this->db->insert('cart_order',$data)){
            $id = $this->db->insert_id();
            $no = date('His').$id;
            $this->db->where('id',$id)->update('cart_order',array('no'=>$no));
            $items = array();
            foreach ($_POST['items'] as $row){
                $items[] = array('cart_order_id'=>$id,'qty'=>$row['qty'],'price'=>$row['harga_default'],'item_varian_id'=>$row['id'],'item_free'=>$row['item_free'],'catatan'=>$row['catatan']);

            }

            if($this->db->insert_batch('cart_item',$items)){
                echo json_encode(array('success'=>1,'no'=>$no));
            }



        }

best regard

javas
  • 49
  • 6
  • http://php.net/manual/en/function.header.php .. location .. –  Oct 29 '17 at 05:42
  • Please do some googling before posting these kind of trivial questions. Your question was answered [here](https://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – Erfan Ahmed Oct 29 '17 at 05:44
  • Possible duplicate of [How to make a redirect in PHP?](https://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – Erfan Ahmed Oct 29 '17 at 05:44
  • This code is not complete. It should be a part of a web service or API. Do you get the response by ajax in front end or in another php function? There are a lot of confusions around your question! – Navid Oct 29 '17 at 05:53

2 Answers2

0

Use header() function: Like this: header("Location: redirect_web_address");

If you want to redirect "www.mydomain.com/go/4656566665" here. You code is:

header("Location: www.mydomain.com/go/4656566665");

So, paste the code in where your data inserted successfully.

acoder
  • 739
  • 5
  • 19
0

if you want to redirect the user after logging this page in browser's history , you may use JavaScript

die( "<script>location.href='http://example.com/go/".$no."/';");

or if you want to redirect your page before reaching to the browser you may use php header

header("location:http://example.com/go/".$no);
Hasibul Hasn
  • 318
  • 5
  • 16