Jump to content

Recommended Posts

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

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>

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.