Homework issues

Links for php scripts

Moderators: macek, egami, gesf

CerealKiller
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Jan 22, 2012 7:55 am

Homework issues

Postby CerealKiller » Sun Jan 22, 2012 8:55 am

I need some help with my web service homework.
In client.php I have combobox and text field.
Image

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="wsdl.php">
<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</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>

When someone chooses option 3 for example, I need to extract its value 1600 and multiply it by number entered in text field. This should be done in function calculate($opt_value,$num) which is in service.php file, but I can't do that because I don't know how to extract that value to wsdl.php file.
I guess this is wrong in wsdl.php file:

Code: Select all

if(isset($_POST['calculate'])){
      $param = array("opt_value" => $_POST["option_menu"], "num" => $_POST["number"]);
      $result = $client->call('calculate', $param);

Or maybe its the function in service.php file:

Code: Select all

$server->register('calculate', array('opt_value' => 'xsd:int', 'num' => 'xsd:int'), array('return' => 'xsd:int'), 'urn:Result');
   
   function calculate($opt_value, $num) {
      $result = $opt_value * $num;
      return $result;      
   }

As you can probabily see I am new to this php stuff so I was wondering if anyone can help me out?

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

Re: Homework issues

Postby TheProdigyGuy » 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.

CerealKiller
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Jan 22, 2012 7:55 am

Re: Homework issues

Postby CerealKiller » Fri Jan 27, 2012 5:12 am

Thank you so much!


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron