2018
Q.No 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<!DOCTYPE html> <html> <head> <title> Sum of two numbers </title> </head> <body> <form name="My form" method="POST" action=""> <fieldset> <legend>Sum of Two numbers</legend> <label>First Number: <input type="number" name="n1" placeholder="Enter first number" required=""> </label> <br> <br> <label>Second Number: <input type="number" name="n2" placeholder="Enter second number"> </label> <br> <br> <input type="reset" name="reset" value="Reset"> <input type="submit" name="btn" value="SUM"> </fieldset> </form> <!--php code for sum of two numbers--> <?php if(isset($_POST['btn'])) { $firstnum = $_POST['n1']; $secondnum = $_POST['n2']; $sum = $firstnum + $secondnum; echo "The sum of two given number is ".$sum; } ?> </body> </html> |
1 |
1 |
1 |
Q.No 12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<!DOCTYPE html> <html> <head> <title>Associative Array</title> </head> <body> <?php $arr = array( 'a' => 'Bachelor In Information Management', 'b' => 'Bachelor In Business Administration', 'c' => 'Bachelor In Business Studies' ); echo"<h3> Different Faculties </h3>"; foreach($arr as $key => $v1 ){ echo "$key. $v1 <br>"; } ?> </body> </html> |
Q.No 13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<!DOCTYPE html> <html> <head> <title> PHP program to find the difference between two dates </title> </head> <body> <form name="myform" method="POST" action=""> <fieldset> <legend>Difference Between Two Dates</legend> <label>Fisrt Date: <input type="date" name="d1" required=""> </label> <br> <br> <label>Second Date: <input type="date" name="d2" required=""> </label> <br> <br> <input type="reset" name="reset" value="Reset"> <input type="submit" name="btn" value="Difference"> </fieldset> </form> <!--php code--> <?php if(isset($_POST['btn'])) { $d1 = $_POST['d1']; $d2 = $_POST['d2']; $d3 = strtotime($d1); $d4 = strtotime($d2); $diff = abs($d3 - $d4); $years = floor($diff/(365*60*60*24)); echo "The difference between two dates is :".$years; } ?> </body> </html> |
1 |
1 |
1 |
Q.No 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<!DOCTYPE html> <html> <head> <title>Display data from database</title> </head> <body> <?php /*Assume Database Name:'test' Table Name:'info' Column Name:'name','address' */ //connecting database $con = mysqli_connect('localhost','root','','test') or die('Error connecting to database'); $code = 'SELECT * FROM info'; $r = mysqli_query($con,$code) or die('Error in code'); echo "<table border='1' style='border-collapse:collapse';>"; echo "<tr>"; echo "<td align='center'>Name:</td>"; echo "<td align='center'>Address:</td>"; echo "</tr>"; while($res= mysqli_fetch_array($r)) { echo"<tr>"; echo"<td>".$res[0]."</td>"; echo"<td>".$res[1]."</td>"; echo"</tr>"; } echo "</table>"; ?> </body> </html> |
Q.No 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<!DOCTYPE html> <html> <head> <title> Copying of one text file to another </title> </head> <body> <!--php code--> <?php //copying context to 'text1.txt' to 'text2.txt'; //copy function: copy('text1.txt','text2.txt'); $f1 = fopen('text1.txt','r'); $f2 = fopen('text2.txt','w'); while(!feof($f1)) { if(!fwrite($f2,fgets($f1))) die("Error copying"); } echo "Copied"; fclose($f1); fclose($f2); ?> </body> </html><!DOCTYPE html> <html> <head> <title>Display data from database</title> </head> <body> <?php /*Assume Database Name:'test' Table Name:'info' Column Name:'name','address' */ //connecting database $con = mysqli_connect('localhost','root','','test') or die('Error connecting to database'); $code = 'SELECT * FROM info'; $r = mysqli_query($con,$code) or die('Error in code'); echo "<table border='1' style='border-collapse:collapse';>"; echo "<tr>"; echo "<td align='center'>Name:</td>"; echo "<td align='center'>Address:</td>"; echo "</tr>"; while($res= mysqli_fetch_array($r)) { echo"<tr>"; echo"<td>".$res[0]."</td>"; echo"<td>".$res[1]."</td>"; echo"</tr>"; } echo "</table>"; ?> </body> </html> |