A simple function call <html> <body> <?php if(isset($_POST['button'])) { setValue(); // Function is called } function setValue() { echo "<br>The button property to call PHP function works"; // Your code here } ?> <input type="submit" name="button" onclick=<?php $_SERVER['PHP_SELF']; ?> /> </body> </head>
PHP is a recursive acronym for "PHP: Hypertext Preprocessor" created by The PHP Group. PHP is a widely used server-side scripting language and the general purpose of PHP is to create dynamic Web Pages. For more information, visit the PHP website.
Well that's fairly easy, as - if you done it correctly - every checkbox has a name, and if this checkbox has been ticked, the POST or GET variable will hold a value named "on", after submitting the form. A standard code to check wether it has been submitted and checked can be something like: if(isset($_POST['checkbox1']) && !empty($_POST['checkbox1'])){ do something here... } that's it.
"PHP: Hypertext Preprocessor".
< ?php // This is an example of comment in PHP /* This is another example of comment in PHP and we can write comments in multiple lines using this method */ ? >
Its an easy PHP code
A simple function call <html> <body> <?php if(isset($_POST['button'])) { setValue(); // Function is called } function setValue() { echo "<br>The button property to call PHP function works"; // Your code here } ?> <input type="submit" name="button" onclick=<?php $_SERVER['PHP_SELF']; ?> /> </body> </head>
I am certain isset() is working exactly the way it is supposed to. Check that you are using the correct function for what you need to do, it might not be isset() that you want to be use.
Result:
She is a textile artist
Here's a quick example on how to do it. <?php if(isset($_POST['send'])) { if($_POST['answer'] == 'My Answer') echo 'You got it!'; else echo 'Wrong answer.'; } ?> <form method="post" action="you_file_name_here"> What is the answer to this question? <br> <input type="text" name="answer"> <input type="submit" name="send" value="Check it!"> </form>
I made a few weeks ago: session_start(); //you can also use a cookie, I prefer session. error_reporting(0); //to avoid notice in checking if counted. if(!isset($_SESSION['cont'])) { //check if not counted yet. error_reporting(E_ALL); //activate error reporting again. $dir = 'PATH FOR THE VAR TO BE SOTRED IN'; //THIS MUST BE A PHP file !! if(include($dir)) { if(isset($cnt)) { $cnt ++; $cntr = '<?php'.sprintf(PHP_EOL).' $cnt = '.$cnt.';'.sprintf(PHP_EOL).' ?>'; file_put_contents($dir, $cntr); $_SESSION['cont'] = true; } else { $cnt = 1; $cntr = '<?php'.sprintf(PHP_EOL).' $cnt = '.$cnt.';'.sprintf(PHP_EOL).' ?>'; file_put_contents($dir, $cntr); $_SESSION['cont'] = true; } } else { echo 'Wrong file path '.$dir; } } Good luck :)
You should write this line of code before any text is sent to the browser. Remember, even the HTML tag counts. So you can type: <?php if (isset($_POST['submit'])) header("location:http://www.mywebsite.com/thankyou.php"); ?> Remember that if statements and other PHP statements that don't actually send output would work, but any output sent to the browser won't. Be careful of that!
This program only suits PHP. If you want a proper one try C program for it available on web <body> <?php if(isset($_POST['submit'])) { $text = $_POST['text']; $string = mysql_real_escape_string($text); $invert = strrev($string); if($string == $invert) { echo "<br>Given number is a palindrome!!"; } else { echo "<br>Given number is not a palindrome!!"; } } ?> <form method="post"> <input type="text" name="text" id="text" /> <input type="submit" name="submit" value="Submit" id="submit" onclick="<?php $_SERVER['PHP_SELF']; ?>" /> </form> </body>
Answer: Php 2510% of Php 250= 10% * Php 250= 0.10 * Php 250= Php 25
You can't actually do that. There is no direct way to make JavaScript code talk to PHP code, as the two languages are interpreted in different locations. The PHP is interpreted by the server, and the JavaScript is interpreted by the client. This means it's easy enough to transfer data from PHP to JavaScript (by generating the JavaScript with the PHP), but not the other way around. If you're simply looking for a way to see if a JavaScript variable is set (from within the JavaScript itself), that can be done with a line like this one: if(myVariable !== undefined){ /* do stuff */} If you actually want to handle it on the PHP side, one way to do so would be to use additional PHP code when that happens. For example: <?php $jsVars = array(); ?> <script type="text/javascript"> var foo = 'bar'; <?php $jsVars['foo'] = 'bar';?> var yub = 'nub'; <?php $jsVars['yub'] = 'nub';?> </script> ... You can then check to see whether a certain variable has been set by seeing if it's in that array: <?php function jsIsset($varname){ global $jsVars; return array_key_exists($varname, $jsVars); } ?> This however, only works when the JavaScript is generated, not when it's interpreted by the client system. For example, imagine you have a variable that is defined by a JavaScript function that is called from an onclick event. By the time that event happens, the page has already been served and the PHP is done executing. If you want the JavaScript to tell the PHP that a variable is defined, you would need to do it through an AJAX request, which I believe is beyond the scope of this question.
If it's just a single file, you could do it by adding a counter at the head of the file. Something like this: $incTally = isset($incTally) ? $incTally + 1 : 1; If you need something more elaborate, such as tracking the include frequency for all files, you could do it by adding this code at the top of all files: if(!isset($incTally)){ $incTally = array(); } if(array_key_exists(__FILE__, $incTally)){ $incTally[__FILE__]++; }else{ $incTally[__FILE__] = 1; } Which would give you an array listing the number of inclusions for every file that includes that header.