Results 1 to 4 of 4

Thread: Redirecting page?

  1. #1
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default Redirecting page?

    ok I want to update some fields in my database then redirect the page.

    I have tried using these methods:


    http_redirect();

    Code:
    <?php session_start(); ?>
    
    <?php
    require("conn.php");
    
    $user = $_SESSION['user'];
    
    if(isset($_POST['btnEdit']))
    {
    	$skills = $_POST['skills'];
    	$goals = $_POST['goals'];
    	$achievements = $_POST['achievements'];
    	$aboutme = $_POST['aboutme'];
    	$sql = "UPDATE profile SET skills = '$skills', goals = '$goals', achievements = '$achievements', aboutme = '$aboutme' WHERE username = '$user'";
    	$result = mysql_query($sql) or die ("ERROR UPDATING: " . mysql_error());
    	
    	if($result)
    	{
    		echo "Profile Succesfully Updated!";
    		http_redirect("profile.php?" . $user);
    	}
    }
    
    ?>
    header();

    Code:
    <?php session_start(); ?>
    
    <?php
    require("conn.php");
    
    $user = $_SESSION['user'];
    
    if(isset($_POST['btnEdit']))
    {
    	$skills = $_POST['skills'];
    	$goals = $_POST['goals'];
    	$achievements = $_POST['achievements'];
    	$aboutme = $_POST['aboutme'];
    	$sql = "UPDATE profile SET skills = '$skills', goals = '$goals', achievements = '$achievements', aboutme = '$aboutme' WHERE username = '$user'";
    	$result = mysql_query($sql) or die ("ERROR UPDATING: " . mysql_error());
    	
    	if($result)
    	{
    		echo "Profile Succesfully Updated!";
    		header("Location: profile.php?" . $user);
    	}
    }
    
    ?>
    And finally ob_start(); ob_end_flush();

    Code:
    <?php session_start(); ?>
    
    <?php
    require("conn.php");
    
    $user = $_SESSION['user'];
    
    if(isset($_POST['btnEdit']))
    {
    	$skills = $_POST['skills'];
    	$goals = $_POST['goals'];
    	$achievements = $_POST['achievements'];
    	$aboutme = $_POST['aboutme'];
    	$sql = "UPDATE profile SET skills = '$skills', goals = '$goals', achievements = '$achievements', aboutme = '$aboutme' WHERE username = '$user'";
    	$result = mysql_query($sql) or die ("ERROR UPDATING: " . mysql_error());
    	
    	if($result)
    	{
    		echo "Profile Succesfully Updated!";
                    ob_start();
    		header("Location: profile.php?" . $user);
                    ob_end_flush();
    	}
    }
    
    ?>
    All three of these methods give me errors. I have no idea what to do now, beside just put all the code in one file.

  2. #2
    Join Date
    Sep 2008
    Posts
    26
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    A headerredirect only works if nothing else has been outputted;
    Also there may be no html, no spaces and no linebreaks before the redirect.

    If you want the message "Profile Succesfully Updated!" to appear, use javascript for redirection (and provide a link with "click here if you are not redirected within 5 seconds" or something like that"

  3. #3
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    Thank you for the reply...how would I go about doing that? Would I use the <meta> tag for a time out or just use Javascripts setTimeout(); method?

  4. #4
    Join Date
    Sep 2008
    Posts
    26
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Well, both kind of redirects can be disabled that's why I recomended including a link ... just in case ;-)

    Usualy both will work, if you want to make sure put in both- one with 5 seconds, the other one with 12 (for example).

    If you do not neccesarily need a message you can also use the headerredirect with php which would work in all cases. If you do need a message you could display it on the page that you redirect to, for example

    redirectpage?bla=1&redirmessage=1

    (quick example, you get the point :-) )

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •