Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1) Connect with a database.
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- table, th, td {
- border: 1px solid black;
- }
- </style>
- </head>
- <body>
- <?php
- $servername = "localhost";
- $username = "username";
- $password = "password";
- $dbname = "myDB";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT id, firstname, lastname FROM MyGuests";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- echo "<table><tr><th>ID</th><th>Name</th></tr>";
- // output data of each row
- while($row = $result->fetch_assoc()) {
- echo "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]. "</td></tr>";
- }
- echo "</table>";
- } else {
- echo "0 results";
- }
- $conn->close();
- ?>
- </body>
- </html>
- 2) HTML FORM5
- <!DOCTYPE HTML>
- <html>
- <head>
- <style>
- .error {color: #FF0000;}
- </style>
- </head>
- <body>
- <?php
- // define variables and set to empty values
- $nameErr = $emailErr = $genderErr = $websiteErr = "";
- $name = $email = $gender = $comment = $website = "";
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["name"])) {
- $nameErr = "Name is required";
- } else {
- $name = test_input($_POST["name"]);
- // check if name only contains letters and whitespace
- if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
- $nameErr = "Only letters and white space allowed";
- }
- }
- if (empty($_POST["email"])) {
- $emailErr = "Email is required";
- } else {
- $email = test_input($_POST["email"]);
- // check if e-mail address is well-formed
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $emailErr = "Invalid email format";
- }
- }
- if (empty($_POST["website"])) {
- $website = "";
- } else {
- $website = test_input($_POST["website"]);
- // check if URL address syntax is valid (this regular expression also allows dashes in the URL)
- if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
- $websiteErr = "Invalid URL";
- }
- }
- if (empty($_POST["comment"])) {
- $comment = "";
- } else {
- $comment = test_input($_POST["comment"]);
- }
- if (empty($_POST["gender"])) {
- $genderErr = "Gender is required";
- } else {
- $gender = test_input($_POST["gender"]);
- }
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <h2>PHP Form Validation Example</h2>
- <p><span class="error">* required field.</span></p>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- Name: <input type="text" name="name" value="<?php echo $name;?>">
- <span class="error">* <?php echo $nameErr;?></span>
- <br><br>
- E-mail: <input type="text" name="email" value="<?php echo $email;?>">
- <span class="error">* <?php echo $emailErr;?></span>
- <br><br>
- Website: <input type="text" name="website" value="<?php echo $website;?>">
- <span class="error"><?php echo $websiteErr;?></span>
- <br><br>
- Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
- <br><br>
- Gender:
- <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female
- <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male
- <span class="error">* <?php echo $genderErr;?></span>
- <br><br>
- <input type="submit" name="submit" value="Submit">
- </form>
- <?php
- echo "<h2>Your Input:</h2>";
- echo $name;
- echo "<br>";
- echo $email;
- echo "<br>";
- echo $website;
- echo "<br>";
- echo $comment;
- echo "<br>";
- echo $gender;
- ?>
- </body>
- </html>
- 3)Send email to someone
- <!DOCTYPE html>
- <html>
- <body>
- <h2>Send e-mail to someone@example.com:</h2>
- <form action="mailto:someone@example.com" method="post" enctype="text/plain">
- Name:<br>
- <input type="text" name="name"><br>
- E-mail:<br>
- <input type="text" name="mail"><br>
- Comment:<br>
- <input type="text" name="comment" size="50"><br><br>
- <input type="submit" value="Send">
- <input type="reset" value="Reset">
- </form>
- </body>
- </html>
- 4)Quiz Application
- <!--<HTML>
- <TITLE>
- LOGIN
- </TITLE>
- <BODY>
- <HR>
- <P ALIGN="CENTER"><FONT COLOR="#0000FF"SIZE="6">
- LOGIN</FONT></P>
- <HR>
- <FORM>
- <P ALIGN="CENTER">
- USERNAME:<INPUT TYPE ="TEXT"NAME="T1"ID="NAME">
- PASSWORD:<INPUT TYPE="PASSWORD"NAME="T2"ID="PASS"></P>
- <P ALIGN -"CENTER:>
- <INPUT TYPE="BUTTON"VALUE="LOGIN"ONCLICK="LOGIN()"></P>
- </FORM>
- </BODY>
- <SCRIPT TYPE="TEXT/JAVASCRIPT">
- FUNCTION LOGIN()
- {
- x=document.getElementByID("name");
- y=document.getElementById("pass");
- if(x.value=="cse"&&y.value=="password")
- {
- window.open("test.html");
- }
- elseif(x.value==""&&y.value=="")
- alert("Please enter your name or password");
- }
- </script>
- </html>-->
- <!--<br />
- <b>Warning</b>: ob_start() [<a href='ref.outcontrol'>ref.outcontrol</a>]: output handler 'ob_gzhandler' cannot be used twice in <b>/home/content/22/4814422/html/designing_quiz_application_using_java_script/index.php</b> on line <b>103</b><br />
- <html>
- <title>
- APTITUDE TEST
- </TITLE>
- <body bgcolor="GREEN">
- <hr><p align="center"><font color="#0000FF"size="6">
- Aptitude Test</Font></P>
- <hr>
- <form>
- <input type="radio" name="r1" ID="radio1">
- <p>pipe problems</p>
- <input type="radio"name="r1"ID="radio2">
- <p>ages problem</p>
- <input type="button"value="CLICK"onclick="go"()></form>
- </body>
- <script type="text/javascript">
- function go()
- {
- ifdocument.getElementByID("radio1")checked==true)
- window.open("pipes.html");
- if(document.getElementByID("radio2").checked==true)
- window.open(ages.html");
- }
- </script>
- </html>-->
- <!--<HTML>
- <TITLE>
- PIPE PROBLEMS
- </TITLE>
- <BODY BGCOLOR="TAN">
- <P ALIGN="CENTER"><FONT COLOR="#0000FFF" SIZE="6">
- PIPE PROBLEMS</FONT></P>
- <form>
- <p align="left">
- 1. Two pipes A and B cam fill a tank in 36 hours and 45 hours respectively. If both the
- pipes are opened simultaneously, how much time will be taken to fill the tank </p>
- <p align="left">
- <input type="radio" value="v1" name="r1">17 hours
- <input type="radio" value="v2" name="r1">18 hours
- <input type="radio" value="v3" name="r1"ID="RADIO3">
- 20 HRS
- <input type="radio"value="v4"name="R1">21 hrs</p>
- <p align="left">
- 2. Two pipes can fill a tnak in 10 hours and 12 hours respecptively while a third pipe
- emites the full tank in 20 hrs. If all the three pipes operate simultaneously, in how much
- time will be tank be filled?</p>
- <p align="left">
- <input type="radio"value="v5"name="r2"id-"radio5>
- 7 hrs 30 min
- <input type="radio" value="v6"name="r2">7 hrs
- <input type="radio" value="v7"name="r2">8 hrs
- <input type="radio" value="v8"name="r2">6 hrs 15min</p>
- <p align="left">
- 3.An electric pump can fill a tank in 3 hrs. Because of a leak in the tank in 3 hrs 30
- minutes to fill the tank is full, how much time will the leak take to empty it?</p>
- <p align="left">
- <input type="radio"value="v9"name="r3">20 hrs
- <input type="radio"value="v10"name="r3">22 hrs
- <input type="radio"value="v11"name="r3">19 hrs
- <input type="radio"value="v12"name="r3">21hrs</p>
- <p align="left">
- 4. A tap can fill a tank in 6hrs after half the tank is filled, three more similar taps are opened.
- What is the total time taken to fill the tank completely?</p>
- <p align ="left"><INPUT TYPE="radio" value="v13"name="r4">3 hrs 15 min
- <input type="radio"value="v14"name="r4" id=:"radio14">3 hrs 45 min
- <input type="radio"value="v15"name="r4">4 hrs
- <input type="radio"value="v16"name="r4">4 hrs 15 min</p>
- <p align="left">
- 5.Pipe A can fill a tank in 5 hrs B in 10 hrs and pipe C in 30 hours. If all the pipes are
- opened in how many hours will the tank be filled</p>
- <p align="left"><input type="radio"value="v17"name="r5">2
- <input type="radio"value="v18"name="r5"id="radio18">2.5
- <input type="radio"value="r19"name="r5"id="radio19">3
- <input type="radio"value="r20"name="r5">3.5</p>
- <p align="center">
- <input type="button"value="submit"name="b1"onclick="validate()"></p>
- <p>your answers are<input type="text"id="answer">%correct</p>
- </form>
- </body>
- <script type="text/javascript">
- function validate ()
- {
- var a=0;
- var b=0;
- var c=0;
- var d=0;
- var e=0;
- if(document.getElementByID('radio3').checked==true)
- a=1;
- if(document.getElementByID('radio5').checked==true)
- b=1
- if(document.getElementByID('radio12').checked==true)
- c=1
- if(document.getElementByID('radio14').checked==true)
- d=1
- if(document.getElementByID('radio19').checked==true)
- e=1
- total=a+b+c+d+e;
- perc=total*100\5;
- document.getElementById('Answer")value=perc;
- }
- </script>-->
- </html>
- <!--<br />
- <b>Warning</b>: ob_start() [<a href='ref.outcontrol'>ref.outcontrol</a>]: output handler 'ob_gzhandler' cannot be used twice in <b>/home/content/22/4814422/html/designing_quiz_application_using_java_script/index.php</b> on line <b>221</b><br />
- <html>
- <title>
- PROBLEMS ON AGES
- </title>
- <body bgcolor="cyan">
- <p align="center"><fontcolor=#0000FF" size="6"
- PROBLEMS ON AGES </FONT></P>
- <FORM>
- <P ALIGN="LEFT">
- 1. Rajeev's age after 15 years will be 5 times his age 5 years back. What is the present
- age of rajeev></p>
- <p align="left">
- <input type="radio"value="v1"name="r1">11
- <input type="radio"name="r1"value="v2">12
- <input type="radio"value="v3"name="r1"id="radio3">10
- <input type="radio"name="r1"value="v4">13</p>
- <palign="left">
- 2. The ages of 2 persons differ by 16 years. If 6 years ago, the elder one be 3 times as
- old as the younger one, find their present ages </p>
- <p align="left">
- <input type="radio"name="r2"value="v5"id="radio5"> 14&30
- <input type="radio"name="r2"value="v6">20&15
- <input type="radio"name="r2"value="v7">19&20
- <input type="radio"name="r2"value="v8">18&50</p>
- <p align="left">
- <input type="radio"name="r3"value="v9">16 years
- <input type="radio"name="r3"value="v10">18 years
- <input type="radio"name="r3"value="v11">cannot be determined
- <input type="radio"name="r3"value="v12">NONE OF THIS</p>
- <p align="left">
- 4. The product of the ages of ankita and nikita is 240. If twice the age of nikita is more
- thank ankita's age by 4 years, what is nikita's age?</p>
- <p align="left">
- <input type="radio"name="r4" value"v13">15 years
- <input type="radio"name="r4" value"v14"ID="radio14">12 years
- <input type="radio"name="r4" value"v15">19 years
- <input type="radio"name="r4" value"v16">21 years</p>
- <p align="left">
- 5. Present ages of x and y are in the ratio 5:6 respectively. Seven years hence this ratio
- will become 6:7 respecptively. What is x's present age in years?</p>
- <p align="left:><<input type="radio"name="r5" value"v17">45 years
- <input type="radio"name="r5" value"v18">42 years
- <input type="radio"name="r5" value"v20">49 years</p>
- <p align ="center">
- <input type="button" value="submit"name="b1"onclick="validate()"></p>
- <p>your answers are
- <input type=text id="answer" name"ti">%correct</p>
- </form>
- </body>
- <script type"text/javascript">
- function validate()
- {
- var a=0;
- var b=0;
- var c=0;
- var d=0;
- var e=0;
- if(document.getElementByID('radio3'). checked==true)
- a=1;
- if(document.getElementByID('radio5'). checked==true)
- b=1;
- if(document.getElementByID('radio12'). checked==true)
- c=1;
- if(document.getElementByID('radio14'). checked==true)
- d=1;
- if(document.getElementByID('radio19'). checked==true)
- e=1;
- total=a+b+c+d+e;
- perc=(total*100)/5;
- if(total==5)
- document.getelementById('ANSWER').value=100;
- if(total<5)
- document.getelementById('ANSWER')value=perc;
- }
- </script>
- </html>-->
- 5)To search and display
- Chems.html
- <html>
- <head>
- <script type="text/javascript">
- function loadXMLDoc(){
- var xmlhttp;
- var data = (t1.value);
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();}
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
- }}
- IP LAB MANUAL
- 42
- Ms.B.NIRMALA AP/CSE
- xmlhttp.open("GET","chems.jsp?t1="+data,true);
- xmlhttp.send(); }
- </script>
- </head>
- <body>
- <table>
- <tr><td witdh=150> Enter the Chem Name : </td>
- <td> <Input type=text name=t1 ></td>
- </tr>
- <tr><td witdh=150> Chem Name : </td><td> <div id="myDiv"></div></td>
- </tr>
- <tr><td> <button type="button" onClick="loadXMLDoc()">Change Content</button></td>
- </tr>
- </table>
- </body>
- </html>
- chems.jsp
- <%
- String d=request.getParameter("t1");
- String[]name;
- int i=0,n=0;
- name=new String[10];
- name[0]="atomic number";
- name[1]="catalyst";
- name[2]="acid";
- name[3]="base";
- name[4]="bond energy";
- name[5]="chain reactons";
- name[6]="covalent bonds";
- name[7]="element";
- name[8]="enzyme";
- name[9]="kinetics";
- String[] defn;
- defn=new String[10];
- defn[0]="It is defined as the number of protons or electrons.";
- defn[1]="a catalyst is a substance which fastens a reaction without themselves undergoing any change.";
- defn[2]="An agent able to produce positively charged hydrogen ions.";
- defn[3]="A base is a substance that can combine with a proton.";
- defn[4]="The energy required to break a particular bond by hompolytic process.";
- defn[5]="chain reaction:reactions which proceed by means of a set of repeating cyclic steps.";
- IP LAB MANUAL
- 43
- Ms.B.NIRMALA AP/CSE
- defn[6]="Linkage of two atoms by the sharing of two electrons.";
- defn[7]="a substance which cannot be further subdivided by chemical methods.";
- defn[8]="a naturally occuringb substance able to catalyse a chemical reaction.";
- defn[9]="The study of rate of reactions.";
- for(i=0;i<9;i++) {
- if(d.equals(name[i]))
- n=i; }
- out.println(defn[n]);
- %>
- 5) To display the time
- <html>
- <body>
- <script type="text/javascript">
- var d=new Date()
- document.write(d.getUTCHours())
- document.write(".")
- document.write(d.getUTCMinutes())
- document.write(".")
- document.write(d.getUTCSeconds())
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment