pellio Posted November 10, 2008 Share Posted November 10, 2008 hi im just starting to learn php and have been trying to write a small script where you select which colour you want a block of text to be using a form and the next page outputs a paragraph in that colour. it looks like iv done it correctly but it isnt working. can anyone suggest where iv went wrong?cheers here is page1 code: <?php session_unset(); ?> <html> <head> <title>Choose Formatting</title> </head> <body> <p> Choose the colour of the text: </p> <form method="post" action="formattingoutput2.php"> <select name="colour"> <option value="blue">blue</option> <option value="green">green</option> <option value="red">red</option> </select> <input type="submit" name="submit" value="submit"> </form> </body> </html> page2 code: <?php session_start(); $_SESSION['colour'] = $_POST['colour']; ?> <html> <head> <title>formattingoutput2</title> </head> <body> <?php echo "<p color='"; echo $_SESSION['colour']; echo "'>"; echo "fjgfdhgfhgdhgfdjgfghjfdhgfdhjghfdjghhgjdfhgdfhghfjgfdjghhgf"; echo "</p>"; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/132173-selecting-text-colour-via-a-form/ Share on other sites More sharing options...
.josh Posted November 10, 2008 Share Posted November 10, 2008 that's because color isn't a valid attribute for < p > you can use the <font color='...' > or <p style='color: ...' > Link to comment https://forums.phpfreaks.com/topic/132173-selecting-text-colour-via-a-form/#findComment-686948 Share on other sites More sharing options...
pellio Posted November 10, 2008 Author Share Posted November 10, 2008 cheers also iv got another one kinda similar where iv wrote a css file defining colours as variables then output it as php,brought it into another page and tried to apply the style but again doesnt seem to work.any ideas?? here is the css page called phpcolour.php: <?php header("Content-type: text/css"); $blue = '#0000FF'; $black = '#000000'; $red = '#FF0000'; ?> .text { color:<?=$blue?>; } .text2 { color:<?=$red?>; } .text3 { color:<?=$black?>; } page2 code: <html> <head> <title>Formatting Output</title> <link rel="stylesheet" media="screen" type="text/css" href="phpcolor.php"> </head> <body> <p class="text3"> dghghfgdhf ghdgfhdgfhj gdhjfghjdgfhjd sgfhgdshfhjdgf hjdgfhjgdfhjgdhfghjdsfg ghgdshjf ghghjg gsfhjgdhj ghghg gjhghjg ggggggg ggggggggggggghjgh jghjfghdjsgfhjds ghfjgdhfgh dsgfhdsghfgdhf ghdgfhdshfgdhsg jhjghfghfhgjfh ghfjghdfjghfj dhgjfdhgjdfjghjdfh gjhfdjhgjdfhj ghfdjghfdjghfdgh fdhjghfjhgfhd jhgfdhhgjfhgkfhgj fdhgjfjgfgjgh jfhgfjhgjfdh gjfdhgjfhgjfd hgjfhdkghkdfgfhg fjhjghjfhjgh dfjhgjfdhgg </p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/132173-selecting-text-colour-via-a-form/#findComment-686965 Share on other sites More sharing options...
Barand Posted November 10, 2008 Share Posted November 10, 2008 Closing this thread before anyone wastes time answering a double post. Link to comment https://forums.phpfreaks.com/topic/132173-selecting-text-colour-via-a-form/#findComment-687039 Share on other sites More sharing options...
Recommended Posts