Posts

Showing posts from April, 2017

Write a script to solve following questions(use “Book.xml” file) A:- Create a Dom document object and load this xml file. B:- Get the output of this document to the browser. C:- Save this [.xml] document in another format that i.e. in [.doc]. D:- Write a xml program to print the names of the books available in “Book.xml” file.

Book.xml <?xml version="1.0" encoding="utf-8"?> <ABCBOOK>         <Technical>         <BOOK>         <Book_PubYear>ABC</Book_PubYear>         <Book_Title>pqr</Book_Title>         <Book_Author>400</Book_Author>         </BOOK>         </Technical>          <Cooking>         <BOOK>         <Book_PubYear>ABC</Book_PubYear>         <Book_Title>pqr</Book_Title>         <Book_Author>400</Book_Author>         </BOOK>...

Write an application where String is loaded from ”Dont_forget.xml”  file in php using simplexml_load_string().

Dont_forget.xml:::---   <?xml version='1.0' encoding='UTF-8'?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> Dont_forget.php:::--- <?php $xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object"); print_r($xml); ?>

Create an XML file which gives details of books available in “ABC Bookstore” from following categories. 1)      Technical 2)      Cooking 3)      Yoga And elements in each category are in the following format.     …….     …….     ……. Save the file as “Book.xml” Create an application that reads “Book.xml” file into simple XML object. Display attributes and elements. (Hint:- Use simple_xml_load_file() function). 

Book.XML <?xml version="1.0" encoding="utf-8"?> <ABCBOOK>         <Technical>         <BOOK>         <Book_PubYear>ABC</Book_PubYear>         <Book_Title>pqr</Book_Title>         <Book_Author>400</Book_Author>         </BOOK>         </Technical>          <Cooking>         <BOOK>         <Book_PubYear>ABC</Book_PubYear>         <Book_Title>pqr</Book_Title>         <Book_Author>400</Book_Author>         </BOOK>...

Create an application that reads “Book.xml” into simple XML object. Display attributes and elements. (Hints:- use simplexml_load_file() function).

BOOK.XML <?xml version="1.0" encoding="utf-8"?> <BOOKINFO>       <BOOK>         <bookname>ABC</bookname>         <author>pqr</author>         <price>400</price>       </BOOK>       <BOOK>         <bookname>DEF</bookname>         <author>xyz</author>         <price>300</price>       </BOOK> </BOOKINFO> BOOK.PHP <?php     $xml=simplexml_load_file("Book.xml") or die("cannnot load");    $xmlstring=$xml->asXML();    echo $xmlstring; ?>

Write an Ajax program to print the content of the myfile.dat. This code asks the user to click a button, fetches data from the server using Ajax techniques and displays that data in the same web page as the button without refreshing the page

Fetch.php <html> <head> <script language="javascript"> varreq=false; if(window.XMLHttpRequest) { req=new XMLHttpRequest();  } else  if(window.ActiveXObject) { req=new ActiveXObject("Microsoft.XMLHttp"); } functionfetchdata(datasource,divID) { if(req)   { req.open("GET",datasource); req.onreadystatechange=function()                 { if(req.readyState==4 &&req.status==200)                     { document.getElementById(divID).innerHTML=req.responseText;                     }                } req.send(null);       }   } </script> </head> <body> <form> <input type...

Write a simple PHP program which implements Ajax for addition of two numbers

Add.php <html> <head>    <script language="javascript" src="ajax.js">    </script> </head> <body> <div id="txt" name="txt"></div>    <form action="javascript:add(document.getElementById('frm'));" name="frm" id="frm">   <table>    <tr>      <td>Enter first number : </td>      <td><input type="text" id="num1"></td>      </tr>      <tr>      <td>Enter second number : </td>      <td><input type="text" id="num2"></td>      </tr>      <tr>        <td colspan="2"><input type="submit" name="button" value="show"></td>      </tr> </table> </form> </body> ...

Write a PHP script to demonstrate the introspection for examining class(use function get_declared_classes() ,get_class_methods() and get_class_vars()).

<?php classMyclass           { public $a; public $b=10; public $c='ABC'; functionMyclass()             {               //Myclass function             } function myfun1()             {                //functin             } function myfun2()             {                //functin             }           } $class=get_declared_classes(); foreach($class as $cname) { echo"$c...

Consider the following relational database: Project (P_Group_No, Project_Title) Student (Seat no, Name, Class, P_Group_No) Write a PHP script to accept project title and display list of students those who are working in a particular project.

Project.html <html> <body> <form method=get action="Project.php"> Enter Project Tittle : <input type=text name="pname"><br><br> <input type=submit value="Display"> </form> </body> </html> Project.php <?php          $pname=$_GET['pname']; mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("userpass") or die(mysql_error());          $result=mysql_query("SELECT * FROM student WHERE pgno IN (SELECT pgno FROM project WHERE ptittle = '".$pname."')"); while($row=mysql_fetch_array($result))          { echo"Seat No = ".$row['sno']."  Name  = ".$row['name']; echo"  Class =  ".$row['class']." Proj. Group No. =  ".$row['pgno']."<br>";         } ?>

Write a PHP program to accept username and password from the user. Validate it against the login table in the database. If there is a mismatch between username and password, then, display the error message as ―invalid user name and password; else display the message as ―Login successful‖ on the browser.

Userpass.html <html> <body> <form method=post action="Userpass.php"> Enter UserName : <input type=text name="t1"><br><br> Enter Password   : <input type=text name="t2"><br><br> <input type=submit value="Log In"> </form> </body> </html> Userpass.php <?php           $user=$_POST['t1'];           $pass=$_POST['t2']; mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("userpass") or die(mysql_error());          $result=mysql_query("select * from login"); while($row=mysql_fetch_array($result))          {            if((strcmp($user,$row['user'])==0) && (strcmp($pass,$row['pass'])==0)) echo"Login Successful"; else echo"Invalid user";    ...

Write a PHP program to accept two string from user and check whether entered strings are matching or not.(use sticky form concept)

Sticky.php <html> <body> <form method=post action="Sticky.php"> <fieldset> <legend>Enter Strings in the text Boxes !</legend> <p><b>String1 :</b><input type=text name=s1 value="<?php if(isset($_POST['s1'])) echo $_POST['s1'];?>"></p> <p><b>String2 :</b><input type=text name=s2 value="<?php if(isset($_POST['s2'])) echo $_POST['s2'];?>"></p> </fieldset> <div align=center> <input type=submit name=submit value="submit string"> </div> <input type="hidden" name="submit" value=true> </form> <?php if(isset($_POST['submit']))      {             $s1=$_POST['s1'];             $s2=$_POST['s2']; if(strcmp($s1,$s2)==0) echo"<br><b>Matching</b>"; else echo"<br><b>Not Matching</b>";  ...

Define an interface which has methods area(), volume(). Define constant PI. Create a class cylinder which implements this interface and calculate area and volume.

<?php interfaceCyl         { function area(); function volume();         } class Cylinder implements Cyl         { public $PI=3.14; public $a; public $r; public $h; function __construct($r,$h)            {                 $this->r=$r;                 $this->h=$h;            } function area()            {               $this->a=2*$this->PI*($this->h*$this->r); echo"Area = ".$this->a."<br>";             } function volume(...

A college has given roll number to each student, The roll number is six digit number where first two digits are faculty(B.Sc., BCA, BA) third digit is year (Ist(1), IInd(2) and IIIrd(3)) and last three digit are actual number. Write PHP script to accept a number and print faculty, year and roll number of student.(e.gRollno=BC1004,faculty=BCA, year=1st,rollno=004)

Student.html <html> <body> <form method=get action="student.php"> Enter  <input type=text name="a"><br> <input type=submit value=submit> </form> </body> </html> //Student.php <?php $a=$_GET['a']; if(ereg("^BC|A|S([1-3])([0-9][0-9][0-9])$",$a)) { echo"Roll no = ".substr($a,3)."<br>";    $year=substr($a,2,1); if($year=='1') echo"Year = 1st <br>"; if($year=='2') echo"Year = 2nd <br>"; if($year=='3') echo"Year = 3rd <br>";   $fac=substr($a,0,2); if($fac=='BA') echo"Faculty = BA"; if($fac=='BC') echo"Faculty = BCA"; if($fac=='BS') echo"Faculty = B.Sc."; } else { echo"Invalid "; } ?>

Write a PHP script to accept a string and then display each word of string in reverse order.         (use concept of self processing form)

//StringRev.php <html> <body> <form method=post action="<?php echo $_SERVER['PHP_SELF'] ?>"> Enter String : <input type=text name=str1><br> <input type=submit name=submit> </form> <?php if(isset($_POST['submit']))             {               $str=$_POST['str1'];               $nstr=strrev($str); echo"<br>".$nstr;             } ?> </body> </html>

Write a PHP Script to display Server information in table format (Use $_SERVER).

//ServerInfo.php <?php echo"<table border=1>"; foreach($_SERVER as $k=>$v)            { echo"<tr><td>".$k."</td><td>".$v."</td></tr>";            } echo"</table>"; ?>

Write a PHP Script to Upload the file and display its information.(use $_FILES). 

FileUpload.html <html> <body> <form method=post action="Uploadfile.php" enctype="multipart/form-data"> File Name : <input type="file" name="file" id="file" size=40%><br> <input type=submit name=submit value=submit> </form> </body> </html> Uploadfile.php <?php if($_FILES["file"]["error"]>0)            { echo"Error : ".$_FILES["file"]["error"]."<br>";            } else            { echo"Upload File : ".$_FILES["file"]["name"]."<br>"; echo"Type : ".$_FILES["file"]["type"]."<br>"; echo"Size : ".($_FILES["file"]["size"]/1024)." kb<br>"; echo"Temporary Storage : ".$_FILES["file"]["tmp_name"];            } ?>

Create a form to accept employee details like name, address and mobile number. Once  the employee information is accepted, then accept LIC information like policy_no, name, premium. Display employee details and LIC details on next form.(use COOKIE)

Employee.html <html> <body> <form method=get action="lic.php"> Enter Employee Name : <input type=text name=ename><br> Enter Address : <input type=text name=address><br> Enter Mobile No.<input type=text name=mobile><br> <input type=submit value=Save> </form> </body> </html> Lic.php <?php        $ename=$_GET['ename'];        $address=$_GET['address'];        $mobile=$_GET['mobile']; setcookie("ename",$ename); setcookie("address",$address); setcookie("mobile",$mobile); echo"Hello $ename enter your LIC details <br><br>"; echo"<form method=get action=display.php>                  Policy No.:<input type=text name=pno><br>                ...

Write a Calculator class that can accept two values, then add them, subtract them, multiply them together, or divide them on request. For example: $calc = new Calculator( 3, 4 ); echo $calc- >add(); // Displays “7” echo $calc- >multiply(); // Displays “12”

Calculate.html <HTML><BODY> <FORM method=get action="Calculate.php"> Enter first value: <INPUT type=text name="a"><br> Enter second value:<INPUT type=text name="b"><br> <INPUT type=submit value=”Calculate”> </FORM></BODY></HTML> Calculate.php <?php class Calculate       {public $a; public $b; function __construct($a,$b){ $this->a=$a; $this->b=$b; } public function add()          {           $c=$this->a+$this->b; echo"Addition = $c<br>";          } public function subtract()          {           $c=$this->a-$this->b; echo"Subtract = $c<br>";          } public function multiply()       ...

Write a PHP program to create a simple calculator that can accept two numbers and perform operations like add, subtract, multiplication and divide (using Self Processing form)

Calculator.php <HTML> <BODY> <FORM method=POST action="<?php echo $_SERVER['PHP_SELF'] ?>"> Enter   First   Value  :<INPUT type=text name=a><BR><BR> Enter Second Value:<INPUT type=text name=b><BR><BR> <b>Select Arithmetic Operation</b><BR><BR> <INPUT type=radio name="choice" value="1">Addition<BR><BR> <INPUT type=radio name="choice" value="2">Subtraction<BR><BR> <INPUT type=radio name="choice" value="3">Multiplication<BR><BR> <INPUT type=radio name="choice" value="4">Division<BR><BR> <INPUT type=submit name=submit value="Calculate"><BR> </FORM> <?php          $c=""; if(isset($_POST['submit']))          {            $a=$_POST['a'];     ...