adamjones Posted October 31, 2008 Share Posted October 31, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/ Share on other sites More sharing options...
Maq Posted October 31, 2008 Share Posted October 31, 2008 Please echo out your $data['theme'] to make sure it's the correct path. Also, do you have display errors turned on? Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679418 Share on other sites More sharing options...
rhodesa Posted October 31, 2008 Share Posted October 31, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679419 Share on other sites More sharing options...
Maq Posted October 31, 2008 Share Posted October 31, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679424 Share on other sites More sharing options...
adamjones Posted October 31, 2008 Author Share Posted October 31, 2008 It's so admins can set a theme in the admin panel, eg: christmas, easter, etc.. ...and the output is: location:/ Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679425 Share on other sites More sharing options...
Maq Posted October 31, 2008 Share Posted October 31, 2008 So is this from a drop down menu or something? How do you pass this variable to this page? What's the output when you print out $data['theme']? We need more information... Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679426 Share on other sites More sharing options...
adamjones Posted October 31, 2008 Author Share Posted October 31, 2008 @ Maq: Notice: Undefined variable: data in /home/wowdream/public_html/index.php on line 17 which is this line: print ("location:{$data['theme']}/"); Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679427 Share on other sites More sharing options...
Maq Posted October 31, 2008 Share Posted October 31, 2008 @ Maq: Notice: Undefined variable: data in /home/wowdream/public_html/index.php on line 17 Does this field exist in your table? Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679429 Share on other sites More sharing options...
adamjones Posted October 31, 2008 Author Share Posted October 31, 2008 My table structure is; CREATE TABLE IF NOT EXISTS `theme` ( `theme` varchar(65) NOT NULL default 'christmas', PRIMARY KEY (`theme`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ...if that helps? Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679435 Share on other sites More sharing options...
rhodesa Posted October 31, 2008 Share Posted October 31, 2008 then there must be no rows in the table? how do you manage your table? phpMyAdmin? can you double check there is at least one row in that table and there is a value in the theme column for it? Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679470 Share on other sites More sharing options...
adamjones Posted October 31, 2008 Author Share Posted October 31, 2008 Hi. Yes, there is a row called theme, with is the primary row, and in it 'christmas'. Adam. Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-679723 Share on other sites More sharing options...
rhodesa Posted November 3, 2008 Share Posted November 3, 2008 well, can you post a dump of the table, so i can load it up and test the code? Quote Link to comment https://forums.phpfreaks.com/topic/130889-redirect-to-url-depending-on-database-info/#findComment-681101 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.