0

Okay, the program creates a form where are 3 inputs and user can enter RGB color numbers inside the form and the program prints the dechex of the number and uses the RGB color in the text on the site, I can´t get this working, I think there is a problem with the variable $endcolor, Thx already!

    if (!empty($_POST["red"]) && !empty($_POST["green"]) &&
    !empty($_POST["blue"]))
    {

    $red=$_POST["red"];
    $green=$_POST["green"];
    $blue=$_POST["blue"];
    $redvalue = dechex($red);
    $greenvalue = dechex($green);
    $bluevalue = dechex($blue)."<br>";
    echo "#". $redvalue. $greenvalue. $bluevalue;
    $endcolor = "#".$redvalue.$greenvalue.$bluevalue;
    echo "<p>You chosed <span style=\"color:$endcolor;\">This</span>Color</p>";


    }
    else
    {

    ?>
    <form action="phpharj19.php" method="post">
    Insert red(max 255)<br><input type="value" name="red"><br>
    Insert green(max 255)<br><input type="value" name="green"><br>
    Insert blue(max 255)<br><input type="value" name="blue"><br>
    <input type="submit" value="Lähetä">
    <br>
   <?php
   }
   ?>
niqo
  • 5
  • 3
  • I dont make this an answer but look at this page for rgb2hex() Source: https://bavotasan.com/2011/convert-hex-color-to-rgb-using-php/ Big diff is `str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT)` – JustOnUnderMillions Feb 20 '17 at 16:25

2 Answers2

0

What is the problem? Is the page not showing the color? Is the program not converting rgb to hex?

Check this: Convert RGB to hex color values in PHP

Community
  • 1
  • 1
Condorcho
  • 503
  • 4
  • 12
  • Oh sry I forgot the most important information, the site is not showing the color – niqo Feb 20 '17 at 16:37
  • Well, in your code there isn't any line that specifies to change the site color. You should create a js function that changes it. Let's say, after the last `echo` inside the `if`: `echo "";` – Condorcho Feb 20 '17 at 16:39
  • I have no idea how to do that, I have just started php and this is exercise from my school, I havent used js at all. Can you show me how to do the function? – niqo Feb 20 '17 at 16:48
  • My last comment has the answer to that :) – Condorcho Feb 20 '17 at 16:49
  • It didnt work ;(, I added it after the last echo and tried but nothing changes... – niqo Feb 20 '17 at 16:51
  • Check the link in the answer first, and try to check if your function displays the colors right. Also, try this instead of the above: `echo "";` – Condorcho Feb 20 '17 at 16:54
  • Parse error: syntax error, unexpected '‌​' (T_STRING), expecting ',' or ';' – niqo Feb 20 '17 at 17:01
  • Cant figure out what the heck is going on – niqo Feb 20 '17 at 17:17
0
$bluevalue = dechex($blue)."<br>";

You've got an extra HTML tag in the resulting color-code. That'll break the style tag. Get rid of that and you should be okay.

Rob Wilkins
  • 1,650
  • 2
  • 16
  • 20