3raser Posted June 14, 2010 Share Posted June 14, 2010 The code doesn't seem to do it's job. It basically doesn't echo $link or something, because the styles don't change. <?php //connect to database mysql_connect("$mysql_host","$mysql_user","$mysql_password"); mysql_select_db("$mysql_database"); $extract = mysql_query("SELECT theme FROM themes WHERE ip='$ip'"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_assoc($extract)) { $theme = $row['theme']; } if ($theme=="1") { $link = "style.css"; } if ($theme=="2") { $link = "style2.css"; } ?> <link rel="stylesheet" type="text/css" href="<? echo $link; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/204772-style-doesnt-change-simple-if-1-or-if-2-code/ Share on other sites More sharing options...
Psycho Posted June 14, 2010 Share Posted June 14, 2010 What does the actual HTML code look like? If the value of $theme doesn't EXACTLY equal '1' or '2' then it won't work. You should double check the values in the DB and the values returned from the query. Although you could also make it a little more elegant to always get a value even if ther eis a problem form the query results: <?php //connect to database mysql_connect("$mysql_host","$mysql_user","$mysql_password"); mysql_select_db("$mysql_database"); $query = "SELECT theme FROM themes WHERE ip='$ip'"; $result = mysql_query($query); $theme = result($result, 0); $link = ($theme=='2') ? "style2.css" : ""style.css; ?> <link rel="stylesheet" type="text/css" href="<?php echo $link; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/204772-style-doesnt-change-simple-if-1-or-if-2-code/#findComment-1072057 Share on other sites More sharing options...
3raser Posted June 14, 2010 Author Share Posted June 14, 2010 I already have something that allows people to make them 1 or 2 ONLY. <?php $change_theme = $_GET['themeto']; if (!$change_theme){ } elseif($change_theme=="1" || $change_theme=="2") { $ip = $_SERVER['REMOTE_ADDR']; $query = mysql_query("SELECT * FROM themes WHERE ip='$ip'"); $numrows = mysql_num_rows($query); if ($numrows!=1) { mysql_query("INSERT INTO themes VALUES ('$ip', '$change_theme')"); } else { mysql_query("UPDATE themes SET theme='$change_theme' WHERE ip='$ip'"); } } else { } ?> And the required HTML is already in the first code I posted. Quote Link to comment https://forums.phpfreaks.com/topic/204772-style-doesnt-change-simple-if-1-or-if-2-code/#findComment-1072062 Share on other sites More sharing options...
3raser Posted June 14, 2010 Author Share Posted June 14, 2010 Bump Quote Link to comment https://forums.phpfreaks.com/topic/204772-style-doesnt-change-simple-if-1-or-if-2-code/#findComment-1072085 Share on other sites More sharing options...
Psycho Posted June 14, 2010 Share Posted June 14, 2010 I already told you what to look for. You need to verify the actual data in the database. Then validate the data that is returned from the query. And, you haven't verified what the HTML actually contains. Quote Link to comment https://forums.phpfreaks.com/topic/204772-style-doesnt-change-simple-if-1-or-if-2-code/#findComment-1072098 Share on other sites More sharing options...
3raser Posted June 14, 2010 Author Share Posted June 14, 2010 I already told you what to look for. You need to verify the actual data in the database. Then validate the data that is returned from the query. And, you haven't verified what the HTML actually contains. I found the problem. It didn't have $ip Thank you for the help, VERY APPRECIATED! Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/204772-style-doesnt-change-simple-if-1-or-if-2-code/#findComment-1072102 Share on other sites More sharing options...
3raser Posted June 14, 2010 Author Share Posted June 14, 2010 . Quote Link to comment https://forums.phpfreaks.com/topic/204772-style-doesnt-change-simple-if-1-or-if-2-code/#findComment-1072104 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.