Web Analytics Made Easy -
StatCounter select and remember - CodingForum

Announcement

Collapse
No announcement yet.

select and remember

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • select and remember

    Hello, I am trying to create something that allows a user to select a stylesheet, and to have that stylesheet permanantly used, so it is remembered wqhen they log out and called when they log back in. I have 90% of the code sorted, the following code will let the user select a color, write it to the users "color" field in the database, and then load in the relevant stylesheet based on the radio buttons selection. However i need it to call from the database and replace the current stylesheet with whichever color is present in the db at all times, so that when the user is logged out the styleshhet prefernce is remembered, and called when they re-log in. Any ideas? here is my code and its the last statement i cant seem to get right :

    PHP Code:
    <?php include("include/session.php");?>


    <?php
    if (isset($_POST['Submit1'])) {
    $selected_radio $_POST['color'];
    print 
    $selected_radio;
    ?>
    <html>
    <head>
    <title>My Page</title>

        <?php
    $css1 
    "SELECT `color`  WHERE `users`.`username` = '$session->username' LIMIT 1 ";
    $red_status 'unchecked';
    $blue_status 'unchecked';
    $green_status 'unchecked';

    if (isset(
    $_POST['Submit1'])) {

    $selected_radio $_POST['color'];

        if (
    $selected_radio == 'red') {
            
    $qry"UPDATE `users` SET `color` = 'red' WHERE `users`.`username` = '$session->username' LIMIT 1 ";
            
    $red_status 'checked';
        echo 
    "<link href=\"css/red.css\" media=\"all\" rel=\"stylesheet\" type=\"text/css\">";
    }
        else if (
    $selected_radio == 'blue') {

            
    $qry"UPDATE `users` SET `color` = 'blue' WHERE `users`.`username` = '$session->username' LIMIT 1 ";
            
    $blue_status 'checked';
        echo 
    "<link href=\"css/blue.css\" media=\"all\" rel=\"stylesheet\" type=\"text/css\">";
    }
        else if (
    $selected_radio == 'green') {
            
    $qry"UPDATE `users` SET `color` = 'green' WHERE `users`.`username` = '$session->username' LIMIT 1 ";
            
    $green_status 'checked';
        echo 
    "<link href=\"css/green.css\" media=\"all\" rel=\"stylesheet\" type=\"text/css\">";
    } else (
       
    *
    // this is the line i cant seem to get right
     
       
    echo " <link rel=\"stylesheet\" type=\"text/css\" href=\"css/\""; echo "$css1"; echo"\">";?>
        
    )



    $result = mysql_query($qry);

    }

    ?>
    Thankyou in advance for any help

    Dan

  • #2
    Try
    PHP Code:

    $result 
    mysql_query($css1);
    $row mysql_fetch_assoc($result);

    echo 
    '<link rel="stylesheet" type="text/css" href="css/'.$row["color"].'">'
    Also you have a close php sign on there which stops the php processor and then more php lines below which can't be right.
    Last edited by timgolding; Apr 5, 2009, 03:26 PM.
    You can not say you know how to do something, until you can teach it to someone else.

    Comment


    • #3
      Also i can't imagine that your update querties will be working because you need to run mysql_query on the update strings.
      You can not say you know how to do something, until you can teach it to someone else.

      Comment

      Working...
      X