0

As the title says, I am trying to use a PHP variable in inline CSS code. Here is what I have for the CSS:

<style>
    p {
    text-align: center;
    }

    img{ 
        -moz-animation:<?php $_POST["rmp"]; ?>s rotateRight infinite linear; 
        -webkit-animation:.6s rotateRight infinite linear; 
    }

    @-moz-keyframes rotateRight{
        0%{ -moz-transform:rotate(0deg); -moz-transform-origin:50% 50%; }
        100%{ -moz-transform:rotate(360deg); }
    }

    @-webkit-keyframes rotateRight{
        0%{ -webkit-transform:rotate(0deg); -webkit-transform-origin:50% 50%; }
        100%{ -webkit-transform:rotate(360deg); }
    }
</style>

Here is the HTML/PHP:

<body>
    <img src="http://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Blue_circle_with_white_highlight.svg/547px-Blue_circle_with_white_highlight.svg.png" alt="wheel">

    <form action="wheel.php" method="POST">
        RPM: <input type="number" name="rmp">
             <input type="submit" value="Submit">
    </form>
    <?php
        echo $_POST["rmp"];
    ?>
</body>

DEMO (Works differently in Firefox and Chrome)

0

2 Answers 2

3

You have to use print or echo, so change this:

<?php $_POST["rmp"]; ?>

To this:

<?php echo $_POST["rmp"]; ?>
Sign up to request clarification or add additional context in comments.

Comments

1

You need to use echo to actually output the value of the variable.

Furthermore, using inspect element on chrome you can easily see that for your img css you've got the following showing

-moz-animation:<?php $_POST["rmp"];

Instead of it outputting the actual value.

So use <?php echo $_POST["rmp"]; ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.