Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    92
    Thanks
    38
    Thanked 0 Times in 0 Posts

    PHP AND CSS not working

    I have the following code and have endless problems with CSS not working or working intermittently.
    Let me explain:
    I have a textbox named "error" where I want to change the background color and text color but it does not seem to want to do that.

    Below my code, everything works except the CSS in-line style and CSS external file.

    Code:
    <?php
     
    	require "config.php";
    	// Variables declared
    	$result = 0.0;
    	$error = "";
    	
    	// Checking if the form fields are set (with research on the internet I found that it is better to check all fields and not just $Submit=$_POST['Submit'] as it is unstable with IE).
    	if (isset($_POST['num1']) && isset($_POST['num2'])) {
    		// Variables declared if num1 and num2 isset
    		$num1 = $_POST['num1'];
    		$num2 = $_POST['num2'];
    		$function = $_POST['operator'];
    		
    		// If num1 and num2 are numeric check next conditional statement
    		if( is_numeric($num1) && is_numeric($num2) ){
    			// If a operator is selected run through switch cases
    			if($function != null){
    				switch ($function) {
    					case "+":	
    						$result = $_POST[num1] + $_POST[num2];
    						break;
    					case "-":
    						$result = $_POST[num1] - $_POST[num2];
    						break;
    					case "*":
    						$result = $_POST[num1] * $_POST[num2];
    						break;
    					case "/":
    						$result = $_POST[num1] / $_POST[num2];
    						break;
    				}
    			}
    			// If an operator is not selected echo error message
    			else {
    				$error = "You must select an operator!";
    			}
    
    		}
    		// If num1 and num2 are not numeric echo error message
    		else {
    				$error = "You must enter numeric values!";
    			}
    	}
    ?>
    
    <!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Calc Page - 48323934 - ICT 3612</title>
    <meta name="Description" content="Advance PHP ICT3612 Assignment 1. 48323934 - Calc Page" />
    <meta http-equiv="content-language" content="en-za" />
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="Author" content="S.J. Fouche, Student number: 48323934" />
    <meta name="HandheldFriendly" content="True" />
    <!-- Link to the external style sheet (CSS) -->
    <link rel="stylesheet" type="text/css" href="my_css.css" />
    <!-- Link to the external javascript file -->
    <script type="text/javascript" src="my_javascript.js"></script>
    
    </head>
    
    <body>
    <!-- Used the include feature for the header and links on all pages -->
    <?PHP 
    	require "header.txt";
    
    ?>
    <!-- Page header -->
    <h2 align = "center" style = "margin-top: -10px;">Basic Calculator</h2>
    <!-- Basic form with input boxes and dropdown selection and an output box -->
    <form method = "POST"> 
    <p align="center"><p align="center">
    <strong>Enter first number: </strong><input type = "text" name = "num1" size ="7" style = "text-align: center;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <select name = "operator" size = "4" align = "center" valign = "center" multiple = "true">  
    <option value="+">Add [+] </option>  
    <option value="-">Subtract [-] </option>  
    <option value="*">Multiply[*] </option>  
    <option value="/">Divide [/] </option>  
    </select>&nbsp;&nbsp;&nbsp;&nbsp;
    <strong>Enter second number: </strong><input type = "text" name = "num2"  size = "7" style = "text-align: center;"></p></br>
    <p align="center"><input type="submit" value="Calculate Answer" name="calc">
    <input type = "text" name = "answer" size = "10" style = "text-align: center;" disabled = "disabled" value="<?PHP echo($result) ?>" ></br></br>
    <input type = "text" name = "error" size = "30" disabled = "disabled" style = "text-align: center; background-color: 8888FF; color: FF0000;" value="<?PHP echo($error) ?>" ></p>
    </form>   
    
    
    <!-- PHP Coding -->
    <?PHP
    // Code below will create Code link at the center and bottom of the page
    echo("<p style='position:absolute; bottom:5px; left:49%;'><a href='javascript: calccode()'>Code</a></p>")
    ?> 
    
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    I was going to ignore this topic but having read that you're having problems with an external css file...

    Try checking the headers for the .css file request. If the mime type in the reply headers is anything other than text/css then you're in trouble as mozilla based browsers then seem to ignore it (yet IE is fine with it).

    I had this a while back myself.. css files were being downloaded with a mime type of text/html and that puts a spanner in the works big time.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    see if you can get info from here:

    http://css3generator.com/
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •