edawg Posted November 18, 2006 Share Posted November 18, 2006 Hello,What I want to do is on my home page have 3 radio buttons with different options that will change the sites background picture, now im using an external css file, and im using mysql to hold the file.jpg`s. in my external css file i have a variable next to the background: url('<?php echo $background; ?>'). and i connected this to the database, so i have a default background set. but how can i change the variable when the user selects the radio button from the homepage???. this is where im at......<!-- HTML on index.php --> <form id="changeBG" action="change_bg.php" method="post" title="Change Screen" alt="Change Screen"><input type="radio" name="screen" value="radio1" />Black And White<input type="radio" name="screen" value="radio2" />Neon<input type="radio" name="screen" value="radio3" />Yellow<input type="submit" name="submit" value="CHANGE" /></form><!-- external css file, which is actually a .php file -->#holder {width: 850px;height: 800px;margin: 0;padding: 0;border: 1px solid gray;background: #ffffff url("<?php echo $background;?>") no-repeat;}<!-- php file to handle the radio button inputs -->if (isset($_POST['submit']) && isset($_POST['radio1'])) { $css_id = 2; $sql = "SELECT * FROM site_css WHERE css_id = " .$css_id; if ($result = mysql_query($sql)) { $row = mysql_fetch_array($result); $newbg = $row['css_bg']; global $background = $newbg; } else if {if (isset($_POST['submit']) && isset($_POST['radio2'])) { $css_id = 3; $sql = "SELECT * FROM site_css WHERE css_id = " .$css_id; if ($result = mysql_query($sql)) { $row = mysql_fetch_array($result); $newbg = $row['css_bg']; global $background = $newbg; } else if { if (isset($_POST['submit']) && isset($_POST['radio3'])) { $css_id = 4; $sql = "SELECT * FROM site_css WHERE css_id = " .$css_id; if ($result = mysql_query($sql)) { $row = mysql_fetch_array($result); $newbg = $row['css_bg']; global $background = $newbg; } else { $css_id = 1; $sql = "SELECT * FROM site_css WHERE css_id = " .$css_id; if ($result = mysql_query($sql)) { $row = mysql_fetch_array($result); $newbg = $row['css_bg']; global $background = $newbg; }}=================================================As you can see im very new to php, so just still learning, but if you could help me out that would be great!!,because im not to sure about the global $var yet, but i heard you need to use it if you want to change a variable on a global scale?.any tips would be great. :) Link to comment https://forums.phpfreaks.com/topic/27696-radio-buttons-and-php/ Share on other sites More sharing options...
Adika Posted November 18, 2006 Share Posted November 18, 2006 The php part is bad. Here is the good code:[code]<?phpif (isset($_POST['submit']){ $radio = $_POST['screen']); if($radio==="radio1") { $css_id = 2; } else { if($radio==="radio2") { $css_id = 3; } else { if($radio==="radio3") { $css_id = 4; } else { $css_id = 1; } } } $sql = "SELECT * FROM site_css WHERE css_id = " .$css_id; if ($result = mysql_query($sql)) { $row = mysql_fetch_array($result); $newbg = $row['css_bg']; $background = $newbg; }}?>[/code]One problem is that I don't understand where do you call the external .css (or .php) file in your index.php file? Link to comment https://forums.phpfreaks.com/topic/27696-radio-buttons-and-php/#findComment-126692 Share on other sites More sharing options...
edawg Posted November 18, 2006 Author Share Posted November 18, 2006 I call it in the index.php file --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title><?php echo $title; ?></title><meta name="description" content="<?php echo $description; ?>"><meta name="keywords" content="<?php echo $keywords; ?>"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" type="text/css" href="webb06.php" /></head><body> Link to comment https://forums.phpfreaks.com/topic/27696-radio-buttons-and-php/#findComment-126697 Share on other sites More sharing options...
Adika Posted November 18, 2006 Share Posted November 18, 2006 You cannot call a .php file as css:<link rel="stylesheet" type="[color=red]text/css[/color]" href="webb06.php" />The best thing is to include the webb06.php in to the index page in the head.include("webb06.php"); Link to comment https://forums.phpfreaks.com/topic/27696-radio-buttons-and-php/#findComment-126701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.