Redirecting Pages with PHP causing problems
        Posted  
        
            by 
                psp
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by psp
        
        
        
        Published on 2011-02-21T13:15:44Z
        Indexed on 
            2011/02/21
            15:25 UTC
        
        
        Read the original article
        Hit count: 230
        
I have a page which has a link to a php page which takes data from $_GET and updates a database. After that it returns the user to the homepage with:
header("Location: http://localhost/");
The thing is that this seems to "interrupt" the mysql part of the code. If I remove this redirect, everything in the database is updated, but when I put it back, nothing gets updated...
This is the database update code, I am using a class of mine as a mysql wrapper:
$conn->where('hash',$data1['hash']);
$conn->update(TABLE_ITEMS,$newData1);
$conn->where('hash',$data2['hash']);
$conn->update(TABLE_ITEMS,$newData2);
Notes:
-There is no text or echo()'s on the page and no space before the <?php
Order of Code:
- Data received from $_SESSIONand$_GET
- Data processed and placed into arrays
- Data placed into mysql database
- header();used to redirect page
Code
<?php
require_once('config.php');
import();
if ( isset ( $_GET['g'] ) && isset ( $_SESSION['itemA'] ) && isset ( $_SESSION['itemB'] ) ) {
$itemA = $_SESSION['gameA'];
$itemB = $_SESSION['gameB'];
$newData1 = processData($itemA);
$newData2 = processData($itemB);
$conn->update(TABLE_ITEMS,$newData1);
$conn->update(TABLE_ITEMS,$newData2);
header('Location: http://localhost/');
} else {
    header('Location: http://localhost/');
}
© Stack Overflow or respective owner