dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP doesn't redirect to the specified location

  1. #1
    Join Date
    Nov 2015
    Posts
    16

    Question PHP doesn't redirect to the specified location

    Even if my code has the
    HTML Code:
    header('Location: /user/?tab=captures&msg=updated');
    it doesn't redirect either. How to solve this?

    PHP Code:
        if (isset($_POST['chosen'])) {
            
    $query "UPDATE users SET template = ? WHERE username = ?";
            
    $stmt $tubcConnection->prepare($query);
            
    $stmt->bind_param('ss'$_POST['chosen'], $user);
            
    $stmt->execute();
            
    $stmt->store_result();
            
            if (
    $stmt->affected_rows === 1) {
                
    header('Location: /user/?tab=captures&msg=updated');
            }
        } 
    HTML Code:
        <form id="capture-form" action="/account/?tab=captures" method="post">
            <input type="hidden" id="chosen" name="chosen" value="default" />
        </form>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    20,743
    Do you have error reporting turned on? Most likely cause would be that headers have already been sent by the time you call header(), which would result in a PHP warning. If you want to test it explicitly:
    PHP Code:
            if ($stmt->affected_rows === 1) {
                if(
    headers_sent($file$line)) {
                    die(
    "Headers already sent in $file at line $line");
                }
                
    header('Location: /user/?tab=captures&msg=updated');
            } 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles