#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    104
    Rep Power
    8

    How to redirect after insert


    Hi, after this code, how would I redirect to another url?

    PHP Code:
     $result mysql_query($query)or   
                die (
    mysql_error());   
                   
                }   
            } 
    Many thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    454
    Rep Power
    60
    As long as you haven't output anything yet you would do
    PHP Code:
    header("Location: blah.php"); 
    or
    PHP Code:
    header("Location: http://www.blah.com"); 
    Originally Posted by ghost06
    Hi, after this code, how would I redirect to another url?
    \
    PHP Code:
     $result mysql_query($query)or   
                die (
    mysql_error());   
                   
                }   
            } 
    Many thanks
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    104
    Rep Power
    8
    THanks for the reply. That redirects as soon as the page loads. I don't even see the content and it redirects. I only want to redirect after clicking the submit button and inserting a record.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    113
    Rep Power
    0
    Put the code thedude2010 gave you after your sql.

    That will allow the sql to execute before the redirect.

    Post some of your code and it will be easier to show you how.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    104
    Rep Power
    8
    PHP Code:
    <?php
    if (is_array($_POST['colour']))   
            {   
    $prodid $_POST['prodid']; 
            while (list (
    $key$value) = each ($_POST['colour']))   
                {   
                
    $query "Insert into colourchoice (colour, ProductID) values  ('$value', '$prodid')";   
                
    $result mysql_query($query)or   
                die (
    mysql_error());   
                   
                }   
            }   
     
    ?>
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    113
    Rep Power
    0
    PHP Code:
    <?php 
    if (is_array($_POST['colour']))    
            {    
    $prodid $_POST['prodid'];  
            while (list (
    $key$value) = each ($_POST['colour']))    
                {    
                
    $query "Insert into colourchoice (colour, ProductID) values  ('$value', '$prodid')";    
                
    $result mysql_query($query)or    
                die (
    mysql_error());    
                    
                }    
    Header("Location: blah.php");
            }    
     
    ?>
    Try that. The redirect is after the sql, allowing it to insert into the database, but outside of the loop, allowing it to loop through until it is finished before redirecting

    Comments on this post

    • ghost06 agrees : Awesome!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    104
    Rep Power
    8
    Thanks very much! How come I can't give you points?
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2007
    Posts
    113
    Rep Power
    0
    I dunno, I don't come on here too often so dont know how the sytem works.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    7
    Rep Power
    0

    redirect after insert


    Hi, I am a newby on php and sql statements. I'm working with a java script such as javascript:cargarExterno('medaceptacondiciones.php', 'contenido')

    I need, when update a table, in the sentence $insertGoTo = " " that load a php file using that javascript.

    The reason is that i am using DIVs in order to keep loading files in one index.php, so when insert into table loads the next page in other window.

    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo