You are on page 1of 5

University of Sulaimani

College of Basic Education


Computer Science Department

Web Programming (PHP)


Lab 2- Form

Wria Mohammed
wria.salih@univsul.edu.iq

College of Basic education / Computer Science Department 1 Wria Mohammed


Exercise One:
Create two pages: index.php and page2.php:
first: create the first page (index.php):
<body>
<div>
<p><strong>Enter your info:</strong></p>
<form name="form1" method="post" action="page2.php">
<div>
<label>Your name:</label>
<input type="text" name="name">
<br/><br/>
<label>College:</label>
<input type="text" name="college">
<br/><br/>
<label>Department:</label>
<input type="text" name="department">
<br/><br/>
<input type="submit" name="submit"
value="Submit">
<input type="reset" name="reset" value="Reset">
</div>
</form>
</div>
</body>

College of Basic education / Computer Science Department 2 Wria Mohammed


Also, in page2.php write the following code:

<?php
echo "Hello " . $_POST['name'] . "<br> You are at
college of " . $_POST['college'] . " <br> and study of
". $_POST['department'];
?>

College of Basic education / Computer Science Department 3 Wria Mohammed


Exercise Two: mathematics operators with forms:
create two pages: page_form.php and page_result.php
firstly,
page_form.php
<body>
<div>
<p><strong>Enter two numbers:</strong></p>
<form name="form1" method="post"
action="page_result.php">
<div>
<label>Enter Number One:</label>
<input type="number" name="num1">
<br/><br/>
<label>Enter Number Two:</label>
<input type="number" name="num2">
<br/><br/>

<input type="submit" value="Submit">


<input type="reset" value="Reset">
</div>
</form>
</div>
</body>
College of Basic education / Computer Science Department 4 Wria Mohammed
page_result.php:
<?php

$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
echo 'zhmarai iakam: '. $num1;
echo '<br> zhmarai dwam: '.$num2;
echo '<br> kokrdnawa: '. $num1 + $num2;
echo '<br> ledarkrdn: '.$num1 - $num2;
echo '<br> lekdan: '.$num1 * $num2;
echo '<br> dabash: '.$num1 / $num2;
echo '<br> mawa: '.$num1 % $num2;

College of Basic education / Computer Science Department 5 Wria Mohammed

You might also like