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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.