Jump to content

Redirect to url depending on database info


adamjones

Recommended Posts

Hi.

 

I have this code;

 

<?php
$DB_Server = 'localhost';
$DB_Username = 'wowdream_db';
$DB_Password = 'pass'; 
$DB_Name = 'wowdream_db';

$DB_Conn = @mysql_connect($DB_Server, $DB_Username, $DB_Password) OR die('MySQL error: '.mysql_error());

@mysql_select_db($DB_Name) OR die('MySQL error: '.mysql_error());

$DB_Query = @mysql_query("SELECT * FROM `theme`") OR die('MySQL error: '.mysql_error()); 

while ($data = mysql_fetch_array($DB_Query)) {

$data['theme'] = nl2br($data['theme']);

header("location:{$data['theme']}/");
}
?>

 

It's meant to redirect to 'whatever_the_theme_is/', but it isn't redirecting.

 

Can anyone help?

first, there shouldn't be a WHILE loop. you should only do one location redirect. can you describe what you are trying to accomplish? random theme? user can set their theme?

 

second, i don't see the reason for this:

$data['theme'] = nl2br($data['theme']);

 

last, change this:

header("location:{$data['theme']}/");

to this

print ("location:{$data['theme']}/");
exit;

and post the output

You also have:

 

SELECT * FROM `theme`;

 

which is always going to grab the first style.  If you want a random theme or the user to chose it you need to have something like:

 

SELECT theme_style FROM theme WHERE theme = $user_choice;

 

Please put error reporting on by putting the following at the top of your script:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.