I tried doing this, and it didnt work. Im goign to identify the $css in the else of an if else statement; so when its else, it willl turn the web page that color, but i cant figure out how to acomplish it.

$css = "<style type="text/css">
body {
background -color: #ffoocc;
}";

you need to escape the " in the css/html. example:

$css = "<style type="text/css">
body {
background -color: #ffoocc;
}";

should be

$css = "<style type=\"text/css\">
body {
background -color: #ffoocc;
}";

You could also use the heredoc syntax

$css =<<<CSS
<style type="text/css">
body {
background -color: #ffoocc;
}
CSS;

there can be NO whitespace in front of CSS;

ok cool that worked but it didnt execute that css code it just came up as $css and i tried it with " " and ' ' didnt make a defrence then i tried just putting $css in the else statement didnt work here is my hole coding

PHP code

<DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/
xhtml1-transitional.dtd">
<html xmlns="en" lng="en">
<head>

<title> php is cool </title>
</head>
<body>

<?php

$pizza = $_POST['pizza'];
$taco = $_POST['taco'];

$css = '<style type=\"text/css\">
body {
background -color: #ffoocc;
}";$css = "<style type=\"text/css\">
body {
background -color: #ffoocc;
}';



if ( $pizza > $taco ) { print '<p> pizza is greater </p>';}
else {  print '<p> taco is greater </p> $css';}

?>

</body>
</html>

html code

<DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/
xhtml1-transitional.dtd">
<html xmlns="en" lng="en">
<head>

<title> testing </title>
</head>
<body>
<div>
<form action= "test3.php" method = "post">
<p>
<h1> this form will tell you witch is greater based on what number you put in</h1>
enter a number for pizza <input type="text" name="pizza">
enter a number for taco <input type="text" name="taco">
click enter when your satisfied
<input type="submit" name="submit" value="submit" />

</form>
</div>
</body>
</html>

you can't use variables in string using single quotes. you have to use double quotes.
ex.

else {  print '<p> taco is greater </p> $css';}

should be

else {  print "<p> taco is greater </p> {$css}";}

or use concatenation (don't know how its spelled)

else {  print '<p> taco is greater </p> '.$css;}

k still didnt turn the background to #ffoocc

in the css, there is no space between background and -color

tecknikly actually there is a space before and after the "-" i just messed up a bit ll didnt fix it though im preaty shure that santax errors arnt causing the problem

try this, i fixed the errors.

<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="en" lng="en">
<head>
<title> php is cool </title>
</head>
<body>
<?php

$pizza = $_POST['pizza'];
$taco = $_POST['taco'];

$css = '<style type="text/css">
body {
background-color: #ffoocc !important;
}';

if ( $pizza > $taco ) {
    echo '<p> pizza is greater </p>';
}
else {
    echo "<p> taco is greater </p> {$css}";
}

?>
</body>
</html>

where did you learn that there is a space? according to many sites, there isn't suppose to be.

oh hmm the book i have now i cant tell if it sais space or not the font is a bit funky hmm i guess there isnt a space but i mean by the loks of this it seems like it could be bouth so idk

is $taco greater than $pizza? everything is correct now. view the source of the page and make sure everything is echoing properly.

also, i just noticed that you forgot your closing </style> .

<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="en" lng="en">
<head>
<title> php is cool </title>
</head>
<body>
<?php

$pizza = $_POST['pizza'];
$taco = $_POST['taco'];

$css = '<style type="text/css">
body {
background-color: #ffoocc !important;
}
</style>';

if ( $pizza > $taco ) {
    echo '<p> pizza is greater </p>';
}
else {
    echo "<p> taco is greater </p> {$css}";
}

?>
</body>
</html>

hmm yeah it is um do you think it could have something to do with the doctype?

actually maybe. the doctype was typed wrong.

try this. i have no idea why its not working.

<?php

if ( isset( $_POST['submit'] ) ) {
    $pizza = $_POST['pizza'];
    $taco  = $_POST['taco'];
    $showCSS = false;
    if ( $pizza < $taco ) {
        $showCSS = true;
    }
}
else {
    die( 'Nothing submitted' );
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="en" lng="en">
<head>
<title> php is cool </title>
<?php

if ( $showCSS ) {
    echo <<<CSS
<style type="text/css">
body {
background-color: #ffoocc;
}
</style>
CSS;
}

?>
</head>
<body>
<?php

if ( !$showCSS ) {
    echo '<p> pizza is greater </p>';
}
else {
    echo "<p> taco is greater </p> {$css}";
}

}

?>
</body>
</html>

ohhhh i just figured it out the color was wrong for somreason that color dosent work but when i typed #e2edff if worked cheers mate thank you for all your help also what does the !important mean ?

!important makes sure that color will override any previous body color set earlier in the page. i don't think its need, but I added just to avoid some problems.

its actually ff00cc not ffoocc :)

its actually ff00cc not ffoocc :)

that would help. i didn't notice those weren't numbers.

make sure you mark the thread as solved.

thank you your a cool guy in my book sorry for my trobles i know i can be a hard guy to work with at times

make sure you mark the thread as solved.

oh yeah i was just going to ask about that how do i do that again its been awhile sence i been here

nvm figured it out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.