Jump to content

Recommended Posts

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; ?>" /> 

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; ?>" /> 

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.

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. :)

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.