Write a PHP script to change background color using switch statement|EasyCoding45

 In this Tutorial we are going to learn how we can Write a PHP script to change background color using switch statement

Note:-

            I have used radio button  for selecting the color in HTML page.

Program :-(save it as bgcolor.html)

<html>

<head>

<form method=post action="bgcolor.php">

<input type=radio name=r1 value=1>Red<br>

<input type=radio name=r1 value=2>Blue<br>

<input type=radio name=r1 value=3>Cyan<br>

<input type=radio name=r1 value=4>Yellow<br>

<input type=radio name=r1 value=5>Brown<br>

<input type=submit value=change>

</form>

</head>

</html>


Program :-(save it as bgcolor.php)

<?php


$opt=$_POST['r1'];


switch($opt)

{

case 1:

echo"<body bgcolor=red>";

echo "<h3>Page colour changed Red</h3>";

break;

case 2:

echo"<body bgcolor=blue>";

echo "<h3>Page colour changed Blue</h3>";

break;

case 3:

echo"<body bgcolor=cyan>";

echo "<h3>Page colour changed Cyan</h3>";

break;

case 4:

echo"<body bgcolor=yellow>";

echo "<h3>Page colour changed Yellow</h3>";

break;

case 5:

echo"<body bgcolor=brown>";

echo "<h3>Page colour changed Brown</h3>";

break;

}


?>


Output :-

            





Comments