Category: 4th semester
PHP || old paper solution ||2018
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> |
PHP || 2019 Old Paper Solutions
Q.No 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php function isInList($listOfCountries, $searchValue){ $countries= $listOfCountries; $value= $searchValue; if(in_array($value, $countries)){ echo $value ."is in the list"; } } $countryList= array( "Nepal", "India", "China", "Bangladesh", "Bhutan", "Maldives", "Germany"); isInList($countryList, "Nepal"); ?> </body> </html> |
Q.No 12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<!DOCTYPE html> <html> <head> <title>Insert CSV file</title> </head> <body> <?php $db = mysqli_connect('localhost','root','','insertcsv'); if(!$db){ echo"failed to connect to MySQL"; exit(); } if(($handle = fopen("item.csv","r"))!==FALSE){ while(($row = fgetcsv($handle))!==FALSE){ $query = "INSERT INTO items(description,quality,rate)VALUES('$row[1]','$row[2],'$row[3]')"; if(mysqli_query($db,$query)){ echo "new records created successfully"; } else{ echo "ERROR:".$query."<br>".mysqli_error($db); } } } |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<?php function displayCalendar($month, $year) { /* draw table */ $calendar = '<table border = 1>'; /* table headings */ $headings = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); $calendar .= '<tr><td>' . implode('</td><td>', $headings) . '</td></tr>'; /* days and weeks ... */ $running_day = date('w', mktime(0, 0, 0, $month, 1, $year)); $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year)); $days_in_this_week = 1; // checks how many days are in this week and how many days has been printed $day_counter = 0; /* row for week one */ $calendar .= '<tr>'; /* print "blank" days until the first of the current week */ for ($x = 0; $x < $running_day; $x++) { $calendar .= '<td> </td>'; $days_in_this_week++; } /* keep going with days.... */ for ($list_day = 1; $list_day <= $days_in_month; $list_day++) { $calendar .= '<td>'; /* add in the day number */ $calendar .= $list_day; $calendar .= '</td>'; if ($running_day == 6) { $calendar .= '</tr>'; //if month is running then tr should be opened if (($day_counter + 1) != $days_in_month) { $calendar .= '<tr>'; } $running_day = -1; //running day starts from 0 and end at 6 $days_in_this_week = 0; //afer last day of the week counter has been reset } $days_in_this_week++; $running_day++; $day_counter++; } /* finish the rest of the days in the week */ if ($days_in_this_week < 8 && $days_in_this_week != 1) { for ($x = 1; $x <= (8 - $days_in_this_week); $x++) { $calendar .= '<td> </td>'; } } /* final row */ $calendar .= '</tr>'; /* end the table */ $calendar .= '</table>'; /* all done, return result */ return $calendar; } /* sample usages */ echo '<h2>July 2021</h2>'; echo displayCalendar(7, 2021); echo '<h2>August 2021</h2>'; echo displayCalendar(8, 2021); echo '<h2>September 2021</h2>'; echo displayCalendar(9, 2021); |
Q.No 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php function check($username,$password){ $conn = mysqli_connect("localhost","root","","login") or die(); $sql = "select * from user where uname='$username'"; $result = mysqli_query($conn,$sql); $row = mysqli_num_rows($result); if($row>0){ $rows = mysqli_fetch_assoc($result); if($password==$rows['upass']){ echo "Welcome User ".$rows['uname']; } }else{ header("location:index.php"); } } check("ram sharma","ram123"); ?> |
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 |
<!DOCTYPE html> <html lang="en"> <head> <title>TU Question No.15, 2019</title> </head> <body> <form action="" method="post"> <input type="text" name="name" placeholder="Enter Name" required=""/><br/> <input type="number" name="age" placeholder="Enter Age" required=""/><br/> <input type="checkbox" name="hobbies[]" value="reading"/>Reading <input type="checkbox" name="hobbies[]" value="playing"/>Playing <input type="checkbox" name="hobbies[]" value="singing"/>Singing<br/> <textarea name = "comment" rows="4" cols="30" placeholder="comment here..." required=""> </textarea><br/> <input type="Submit" name="submit" value="Validate"> </form> <?php if(isset($_POST['submit'])){ $name = $_POST['name']; $age = $_POST['age']; $hobbies = $_POST['hobbies']; $hobbylength = count($hobbies); //validation $nameArray = str_split($name); //convert string into array $nameLength = strlen($name); //name if($nameLength<2 && $nameLength>11){ echo "name length shoud be between 2-10"; } //checking for numbers in strings foreach($nameArray as $key){ if(is_numeric($key)){ echo "character as number not allowed in name"; } } //age if($age<16 && $age>56){ echo "Age should be between 16-55"; } //hobbies should be selected if($hobbylength==0){ echo "one hobby should be selected"; } } ?> </body> </html> |
Continue Reading
Database Notes || BIM
Question paper Solution Pre- board Paper SYLLABUS YEAR2023 Syllabus Here 1st Reference Notes Unit 1 Unit 2 Unit 3 Unit 4 Unit 5 Unit 6 2nd Reference Notes Unit 1 Unit 2 Unit 3 Unit 4 Unit 5 Unit 6
Continue Reading