Search the Community
Showing results for tags 'php variables'.
-
Hey! I want to create a website that can test your counting pace. I’ll make colored, square div that change color after 10 to 30 seconds when you hover over it, and then you’ll type down how long you think it took in a form to check if you’re right. My solution to do this is to create the PHP variable $time = rand(10,30), and in CSS get the div:hover transition-delay to be $time. Then, after the form, I need the same variable for if($_POST[timeguess] = $time) {echo “Correct!”}. I have no idea how to access the same variable in both the CSS and HTML, so I hope some of you can help me out! Thanks
-
I have an html form with a field for name, email, and comment. If you are not logged in you have to type these things in manually. They are then stored in javascript variables and run through ajax (which I did not bother to include). The PHP if statement below is supposed to detect if you are logged in, then replace the name and email variables with your username and email automatically (which are stored in PHP variables). The way I have it now does not work at all. How can I replace the value of the javascript variables with the contents of a PHP variable using an if-statement? <script type='text/javascript'> $('.bt-add-com').click(function(){ var theCom = $('.the-new-com'); var theName = $('#name-com'); var theMail = $('#mail-com'); <?php if($username && $userid) : ?> var theName = "<?php $username; ?>"; var theMail = "<?php $email; ?>"; <?php endif; ?> </script>
-
Hey, I am trying to insert my variable into single quote marks. the following code works but does not put the single quote marks around the variable as it is part of the variable... <?php $user_id = get_current_user_id(); $files = glob('wp-content/uploads/'.$user_id.'/*'); natcasesort($files); foreach($files as $file) { echo '<img src="/' . $file . '" onclick="fakeClick(event, document.getElementById(' . $file . '))" />'; } ?> this appears as with now single quote around the emboldened.. <img src="/wp-content/uploads/1/portfolio-sample-main-image.png" onclick="fakeClick(event, document.getElementById(wp-content/uploads/1/portfolio-sample-main-image.png))"> however how I want to appear is as follows... <img src="/wp-content/uploads/1/portfolio-sample-main-image.png" onclick="fakeClick(event, document.getElementById('wp-content/uploads/1/portfolio-sample-main-image.png'))"> as you can see with single quotes... how can I do this? Thanks