Homework issues

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
TheProdigyGuy
New php-forum User
New php-forum User
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

Thu Jan 26, 2012 7:11 pm

Here is my own way:

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<title>Client</title>
</head>
<body>
<div style="width: 800px; margin: 0px auto; padding-top: 80px;">
<form name="form" method="post" action="">
<label style="font-weight: bold">Choose option and enter number:</label>
<br>
<input type="int" name="number">
<select name="option_menu">
<option value="0" selected="selected">Option 0</option>
<option value="1300">option 1</option>
<option value="1400">option 2</option>
<option value="1600">option 3</option>
<option value="1800">option 4</option>
</select>
<input name="calculate" type="submit" value="Calculate">
</form>
</div>
</body>
</html>


<?php
if(!isset($_POST['calculate'])) die('</body></html>');
if(isset($_POST['calculate']))
{
    
   // var_dump($_POST);
    //die;
    
    $x=0;
    $trigger=0;

    foreach($_POST as $keys=>$ints)
    {
        $x++;
        if($x==count($_POST)) break;
        if(!ctype_digit($_POST[$keys]) || !ctype_digit($_POST[$keys]) && ($trigger <2))
        {
            $trigger++;
            echo '<strong>' . $keys . "</strong> Field Is not Valid!<br>";
        }
        else
        {
            $selected=(int)$_POST['option_menu'];
            $number=(int)$_POST['number'];
        }
    }
    unset($keys,$ints);
    if($trigger==0) echo "Result: " . ($number*$selected) . '</body></html>';


/*
----------------------------------------------------------------------------------------------------------
METHOD: POST
URL: http://xxxxxx/self.php
PARAM: number=IMNOTINT&option_menu=METOISNOTINT&calculate=Calculate

OUTP:
<strong>number</strong> Field Is not Valid!<br><strong>option_menu</strong> Field Is not Valid!<br>

----------------------------------------------------------------------------------------------------------

METHOD: POST
URL: http://xxxxxx/self.php
PARAM: number=Junkdata&option_menu=1300&calculate=Calculate

OUTP:
<strong>number</strong> Field Is not Valid!<br>

----------------------------------------------------------------------------------------------------------
 etc....
*/

    
}
Works.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest