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: 150

Filed under:
|
|

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 tag

Order of Code:

  1. Data received from $_SESSION and $_GET
  2. Data processed and placed into arrays
  3. Data placed into mysql database
  4. 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

Related posts about php

Related posts about mysql