command line interface - assigning user input to a variable in php -
am building firs php program, problem facing assigning user input variable
here code
<?php printf("enter student test mark"); $test = read_stdin(); function read_stdin() { $fr=fopen("php://stdin","r"); // open our file pointer read stdin $input = fgets($fr,128); // read maximum of 128 characters $input = rtrim($input); // trim trailing spaces. fclose ($fr); // close file handle return $input; // return text entered } printf("enter student assignment mark"); ?> how can let user input number , assign test variable
<?php if(isset($_post['submit'])) { $test = $_post['marks'];//assigning input value if(isset($test)) { $fr=fopen("php://stdin","r"); // open our file pointer read stdin $input = fgets($fr,128); // read maximum of 128 characters $input = rtrim($input); // trim trailing spaces. fclose ($fr); // close file handle $result = $input; // return text entered } } ?> <form action="#" method="post"> <input type="text" name="marks" placeholder="enter student test mark"> <input type="submit" name="submit" value="submit"> </form> <?php if(empty($result)) { } else { echo ' enter student assignment mark'; } or else can show input box first , assign variables , calculations
Comments
Post a Comment