Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could do it the way that you showed above, but for security's sake you would probably want to do it a little different (your way would allow significant opportunity for XSS).</p> <p>Essentially, you will need to set the <code>$_SESSION</code> global variable to have the style, and that should come directly from the database. If it were me, I would do this:</p> <pre><code>&lt;?php echo "&lt;form&gt;"; echo "&lt;select name=\"theme\" id=\"select-theme\"&gt;"; $sql = "select * from theme"; foreach ($dbh-&gt;query($sql) as $row) { ?&gt; &lt;option value="&lt;?php $row['id'] ?&gt;"&gt;&lt;?php echo $row['th_name'] ?&gt;&lt;/option&gt; &lt;?php } echo "&lt;/select&gt;"; echo "&lt;/form&gt;"; ?&gt; </code></pre> <p>Then, on your postback script, do this:</p> <pre><code>&lt;?php if (isset($_POST['theme']) { // Perform query here to get the link's file, using PDO - watch out for XSS // Note - you may have to call session_start() // depending on your php.ini's settings $_SESSION['style'] = $link; } </code></pre> <p>If you are wanting to do this on the fly with jQuery, you can see the information here: <a href="https://stackoverflow.com/questions/7846980/how-do-i-switch-my-css-stylesheet-using-jquery">How do I switch my CSS stylesheet using jQuery?</a></p> <p>In addition, you would want to persist your changes like this:</p> <pre><code>&lt;script type="text/javascript"&gt; $("#select-theme").on("change", function() { $.post({ url:'yoururl.php', data: { theme: $(this).find("option:selected").value() }); }); </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload