Guest User

Untitled

a guest
May 3rd, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.91 KB | None | 0 0
  1. 1) Connect with a database.
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <style>
  7. table, th, td {
  8. border: 1px solid black;
  9. }
  10. </style>
  11. </head>
  12. <body>
  13.  
  14. <?php
  15. $servername = "localhost";
  16. $username = "username";
  17. $password = "password";
  18. $dbname = "myDB";
  19.  
  20. // Create connection
  21. $conn = new mysqli($servername, $username, $password, $dbname);
  22. // Check connection
  23. if ($conn->connect_error) {
  24. die("Connection failed: " . $conn->connect_error);
  25. }
  26.  
  27. $sql = "SELECT id, firstname, lastname FROM MyGuests";
  28. $result = $conn->query($sql);
  29.  
  30. if ($result->num_rows > 0) {
  31. echo "<table><tr><th>ID</th><th>Name</th></tr>";
  32. // output data of each row
  33. while($row = $result->fetch_assoc()) {
  34. echo "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]. "</td></tr>";
  35. }
  36. echo "</table>";
  37. } else {
  38. echo "0 results";
  39. }
  40.  
  41. $conn->close();
  42. ?>
  43.  
  44. </body>
  45. </html>
  46.  
  47. 2) HTML FORM5
  48.  
  49. <!DOCTYPE HTML>
  50. <html>
  51. <head>
  52. <style>
  53. .error {color: #FF0000;}
  54. </style>
  55. </head>
  56. <body>
  57.  
  58. <?php
  59. // define variables and set to empty values
  60. $nameErr = $emailErr = $genderErr = $websiteErr = "";
  61. $name = $email = $gender = $comment = $website = "";
  62.  
  63. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  64. if (empty($_POST["name"])) {
  65. $nameErr = "Name is required";
  66. } else {
  67. $name = test_input($_POST["name"]);
  68. // check if name only contains letters and whitespace
  69. if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  70. $nameErr = "Only letters and white space allowed";
  71. }
  72. }
  73.  
  74. if (empty($_POST["email"])) {
  75. $emailErr = "Email is required";
  76. } else {
  77. $email = test_input($_POST["email"]);
  78. // check if e-mail address is well-formed
  79. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  80. $emailErr = "Invalid email format";
  81. }
  82. }
  83.  
  84. if (empty($_POST["website"])) {
  85. $website = "";
  86. } else {
  87. $website = test_input($_POST["website"]);
  88. // check if URL address syntax is valid (this regular expression also allows dashes in the URL)
  89. if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
  90. $websiteErr = "Invalid URL";
  91. }
  92. }
  93.  
  94. if (empty($_POST["comment"])) {
  95. $comment = "";
  96. } else {
  97. $comment = test_input($_POST["comment"]);
  98. }
  99.  
  100. if (empty($_POST["gender"])) {
  101. $genderErr = "Gender is required";
  102. } else {
  103. $gender = test_input($_POST["gender"]);
  104. }
  105. }
  106.  
  107. function test_input($data) {
  108. $data = trim($data);
  109. $data = stripslashes($data);
  110. $data = htmlspecialchars($data);
  111. return $data;
  112. }
  113. ?>
  114.  
  115. <h2>PHP Form Validation Example</h2>
  116. <p><span class="error">* required field.</span></p>
  117. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  118. Name: <input type="text" name="name" value="<?php echo $name;?>">
  119. <span class="error">* <?php echo $nameErr;?></span>
  120. <br><br>
  121. E-mail: <input type="text" name="email" value="<?php echo $email;?>">
  122. <span class="error">* <?php echo $emailErr;?></span>
  123. <br><br>
  124. Website: <input type="text" name="website" value="<?php echo $website;?>">
  125. <span class="error"><?php echo $websiteErr;?></span>
  126. <br><br>
  127. Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
  128. <br><br>
  129. Gender:
  130. <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female
  131. <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male
  132. <span class="error">* <?php echo $genderErr;?></span>
  133. <br><br>
  134. <input type="submit" name="submit" value="Submit">
  135. </form>
  136.  
  137. <?php
  138. echo "<h2>Your Input:</h2>";
  139. echo $name;
  140. echo "<br>";
  141. echo $email;
  142. echo "<br>";
  143. echo $website;
  144. echo "<br>";
  145. echo $comment;
  146. echo "<br>";
  147. echo $gender;
  148. ?>
  149.  
  150. </body>
  151. </html>
  152.  
  153.  
  154. 3)Send email to someone
  155.  
  156. <!DOCTYPE html>
  157. <html>
  158. <body>
  159.  
  160. <h2>Send e-mail to someone@example.com:</h2>
  161.  
  162. <form action="mailto:someone@example.com" method="post" enctype="text/plain">
  163. Name:<br>
  164. <input type="text" name="name"><br>
  165. E-mail:<br>
  166. <input type="text" name="mail"><br>
  167. Comment:<br>
  168. <input type="text" name="comment" size="50"><br><br>
  169. <input type="submit" value="Send">
  170. <input type="reset" value="Reset">
  171. </form>
  172.  
  173. </body>
  174. </html>
  175.  
  176. 4)Quiz Application
  177.  
  178. <!--<HTML>
  179. <TITLE>
  180. LOGIN
  181. </TITLE>
  182. <BODY>
  183. <HR>
  184. <P ALIGN="CENTER"><FONT COLOR="#0000FF"SIZE="6">
  185. LOGIN</FONT></P>
  186. <HR>
  187. <FORM>
  188. <P ALIGN="CENTER">
  189. USERNAME:<INPUT TYPE ="TEXT"NAME="T1"ID="NAME">
  190. PASSWORD:<INPUT TYPE="PASSWORD"NAME="T2"ID="PASS"></P>
  191. <P ALIGN -"CENTER:>
  192. <INPUT TYPE="BUTTON"VALUE="LOGIN"ONCLICK="LOGIN()"></P>
  193. </FORM>
  194. </BODY>
  195. <SCRIPT TYPE="TEXT/JAVASCRIPT">
  196. FUNCTION LOGIN()
  197. {
  198. x=document.getElementByID("name");
  199. y=document.getElementById("pass");
  200. if(x.value=="cse"&&y.value=="password")
  201. {
  202. window.open("test.html");
  203. }
  204. elseif(x.value==""&&y.value=="")
  205. alert("Please enter your name or password");
  206. }
  207. </script>
  208. </html>-->
  209. <!--<br />
  210. <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 />
  211. <html>
  212. <title>
  213. APTITUDE TEST
  214. </TITLE>
  215. <body bgcolor="GREEN">
  216. <hr><p align="center"><font color="#0000FF"size="6">
  217. Aptitude Test</Font></P>
  218. <hr>
  219. <form>
  220. <input type="radio" name="r1" ID="radio1">
  221. <p>pipe problems</p>
  222. <input type="radio"name="r1"ID="radio2">
  223. <p>ages problem</p>
  224. <input type="button"value="CLICK"onclick="go"()></form>
  225. </body>
  226. <script type="text/javascript">
  227. function go()
  228. {
  229. ifdocument.getElementByID("radio1")checked==true)
  230. window.open("pipes.html");
  231. if(document.getElementByID("radio2").checked==true)
  232. window.open(ages.html");
  233. }
  234. </script>
  235. </html>-->
  236. <!--<HTML>
  237. <TITLE>
  238. PIPE PROBLEMS
  239. </TITLE>
  240. <BODY BGCOLOR="TAN">
  241. <P ALIGN="CENTER"><FONT COLOR="#0000FFF" SIZE="6">
  242. PIPE PROBLEMS</FONT></P>
  243. <form>
  244. <p align="left">
  245. 1. Two pipes A and B cam fill a tank in 36 hours and 45 hours respectively. If both the
  246. pipes are opened simultaneously, how much time will be taken to fill the tank </p>
  247. <p align="left">
  248. <input type="radio" value="v1" name="r1">17 hours
  249. <input type="radio" value="v2" name="r1">18 hours
  250. <input type="radio" value="v3" name="r1"ID="RADIO3">
  251. 20 HRS
  252. <input type="radio"value="v4"name="R1">21 hrs</p>
  253. <p align="left">
  254. 2. Two pipes can fill a tnak in 10 hours and 12 hours respecptively while a third pipe
  255. emites the full tank in 20 hrs. If all the three pipes operate simultaneously, in how much
  256. time will be tank be filled?</p>
  257. <p align="left">
  258. <input type="radio"value="v5"name="r2"id-"radio5>
  259. 7 hrs 30 min
  260. <input type="radio" value="v6"name="r2">7 hrs
  261. <input type="radio" value="v7"name="r2">8 hrs
  262. <input type="radio" value="v8"name="r2">6 hrs 15min</p>
  263. <p align="left">
  264. 3.An electric pump can fill a tank in 3 hrs. Because of a leak in the tank in 3 hrs 30
  265. minutes to fill the tank is full, how much time will the leak take to empty it?</p>
  266. <p align="left">
  267. <input type="radio"value="v9"name="r3">20 hrs
  268. <input type="radio"value="v10"name="r3">22 hrs
  269. <input type="radio"value="v11"name="r3">19 hrs
  270. <input type="radio"value="v12"name="r3">21hrs</p>
  271. <p align="left">
  272. 4. A tap can fill a tank in 6hrs after half the tank is filled, three more similar taps are opened.
  273. What is the total time taken to fill the tank completely?</p>
  274. <p align ="left"><INPUT TYPE="radio" value="v13"name="r4">3 hrs 15 min
  275. <input type="radio"value="v14"name="r4" id=:"radio14">3 hrs 45 min
  276. <input type="radio"value="v15"name="r4">4 hrs
  277. <input type="radio"value="v16"name="r4">4 hrs 15 min</p>
  278. <p align="left">
  279. 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
  280. opened in how many hours will the tank be filled</p>
  281. <p align="left"><input type="radio"value="v17"name="r5">2
  282. <input type="radio"value="v18"name="r5"id="radio18">2.5
  283. <input type="radio"value="r19"name="r5"id="radio19">3
  284. <input type="radio"value="r20"name="r5">3.5</p>
  285. <p align="center">
  286. <input type="button"value="submit"name="b1"onclick="validate()"></p>
  287. <p>your answers are<input type="text"id="answer">%correct</p>
  288. </form>
  289.  
  290. </body>
  291. <script type="text/javascript">
  292. function validate ()
  293. {
  294. var a=0;
  295. var b=0;
  296. var c=0;
  297. var d=0;
  298. var e=0;
  299. if(document.getElementByID('radio3').checked==true)
  300. a=1;
  301. if(document.getElementByID('radio5').checked==true)
  302. b=1
  303. if(document.getElementByID('radio12').checked==true)
  304. c=1
  305. if(document.getElementByID('radio14').checked==true)
  306. d=1
  307. if(document.getElementByID('radio19').checked==true)
  308. e=1
  309. total=a+b+c+d+e;
  310. perc=total*100\5;
  311. document.getElementById('Answer")value=perc;
  312. }
  313. </script>-->
  314. </html>
  315. <!--<br />
  316. <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 />
  317. <html>
  318. <title>
  319. PROBLEMS ON AGES
  320. </title>
  321. <body bgcolor="cyan">
  322. <p align="center"><fontcolor=#0000FF" size="6"
  323.  
  324. PROBLEMS ON AGES </FONT></P>
  325. <FORM>
  326. <P ALIGN="LEFT">
  327. 1. Rajeev's age after 15 years will be 5 times his age 5 years back. What is the present
  328. age of rajeev></p>
  329. <p align="left">
  330. <input type="radio"value="v1"name="r1">11
  331. <input type="radio"name="r1"value="v2">12
  332. <input type="radio"value="v3"name="r1"id="radio3">10
  333. <input type="radio"name="r1"value="v4">13</p>
  334. <palign="left">
  335. 2. The ages of 2 persons differ by 16 years. If 6 years ago, the elder one be 3 times as
  336. old as the younger one, find their present ages </p>
  337. <p align="left">
  338. <input type="radio"name="r2"value="v5"id="radio5"> 14&30
  339. <input type="radio"name="r2"value="v6">20&15
  340. <input type="radio"name="r2"value="v7">19&20
  341. <input type="radio"name="r2"value="v8">18&50</p>
  342. <p align="left">
  343. <input type="radio"name="r3"value="v9">16 years
  344. <input type="radio"name="r3"value="v10">18 years
  345. <input type="radio"name="r3"value="v11">cannot be determined
  346. <input type="radio"name="r3"value="v12">NONE OF THIS</p>
  347. <p align="left">
  348. 4. The product of the ages of ankita and nikita is 240. If twice the age of nikita is more
  349. thank ankita's age by 4 years, what is nikita's age?</p>
  350. <p align="left">
  351. <input type="radio"name="r4" value"v13">15 years
  352. <input type="radio"name="r4" value"v14"ID="radio14">12 years
  353. <input type="radio"name="r4" value"v15">19 years
  354. <input type="radio"name="r4" value"v16">21 years</p>
  355. <p align="left">
  356. 5. Present ages of x and y are in the ratio 5:6 respectively. Seven years hence this ratio
  357. will become 6:7 respecptively. What is x's present age in years?</p>
  358. <p align="left:><<input type="radio"name="r5" value"v17">45 years
  359. <input type="radio"name="r5" value"v18">42 years
  360. <input type="radio"name="r5" value"v20">49 years</p>
  361. <p align ="center">
  362. <input type="button" value="submit"name="b1"onclick="validate()"></p>
  363. <p>your answers are
  364. <input type=text id="answer" name"ti">%correct</p>
  365. </form>
  366. </body>
  367. <script type"text/javascript">
  368. function validate()
  369. {
  370.  
  371. var a=0;
  372. var b=0;
  373. var c=0;
  374. var d=0;
  375. var e=0;
  376. if(document.getElementByID('radio3'). checked==true)
  377. a=1;
  378. if(document.getElementByID('radio5'). checked==true)
  379. b=1;
  380. if(document.getElementByID('radio12'). checked==true)
  381. c=1;
  382. if(document.getElementByID('radio14'). checked==true)
  383. d=1;
  384. if(document.getElementByID('radio19'). checked==true)
  385. e=1;
  386. total=a+b+c+d+e;
  387. perc=(total*100)/5;
  388. if(total==5)
  389. document.getelementById('ANSWER').value=100;
  390. if(total<5)
  391. document.getelementById('ANSWER')value=perc;
  392. }
  393. </script>
  394. </html>-->
  395.  
  396. 5)To search and display
  397.  
  398. Chems.html
  399. <html>
  400. <head>
  401. <script type="text/javascript">
  402. function loadXMLDoc(){
  403. var xmlhttp;
  404. var data = (t1.value);
  405. if (window.XMLHttpRequest)
  406. {// code for IE7+, Firefox, Chrome, Opera, Safari
  407. xmlhttp=new XMLHttpRequest();}
  408. else
  409. {// code for IE6, IE5
  410. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  411. xmlhttp.onreadystatechange=function()
  412. {
  413. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  414. {
  415. document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  416. }}
  417. IP LAB MANUAL
  418. 42
  419. Ms.B.NIRMALA AP/CSE
  420. xmlhttp.open("GET","chems.jsp?t1="+data,true);
  421. xmlhttp.send(); }
  422. </script>
  423. </head>
  424. <body>
  425. <table>
  426. <tr><td witdh=150> Enter the Chem Name : </td>
  427. <td> <Input type=text name=t1 ></td>
  428. </tr>
  429. <tr><td witdh=150> Chem Name : </td><td> <div id="myDiv"></div></td>
  430. </tr>
  431. <tr><td> <button type="button" onClick="loadXMLDoc()">Change Content</button></td>
  432. </tr>
  433. </table>
  434. </body>
  435. </html>
  436. chems.jsp
  437. <%
  438. String d=request.getParameter("t1");
  439. String[]name;
  440. int i=0,n=0;
  441. name=new String[10];
  442. name[0]="atomic number";
  443. name[1]="catalyst";
  444. name[2]="acid";
  445. name[3]="base";
  446. name[4]="bond energy";
  447. name[5]="chain reactons";
  448. name[6]="covalent bonds";
  449. name[7]="element";
  450. name[8]="enzyme";
  451. name[9]="kinetics";
  452. String[] defn;
  453. defn=new String[10];
  454. defn[0]="It is defined as the number of protons or electrons.";
  455. defn[1]="a catalyst is a substance which fastens a reaction without themselves undergoing any change.";
  456. defn[2]="An agent able to produce positively charged hydrogen ions.";
  457. defn[3]="A base is a substance that can combine with a proton.";
  458. defn[4]="The energy required to break a particular bond by hompolytic process.";
  459. defn[5]="chain reaction:reactions which proceed by means of a set of repeating cyclic steps.";
  460. IP LAB MANUAL
  461. 43
  462. Ms.B.NIRMALA AP/CSE
  463. defn[6]="Linkage of two atoms by the sharing of two electrons.";
  464. defn[7]="a substance which cannot be further subdivided by chemical methods.";
  465. defn[8]="a naturally occuringb substance able to catalyse a chemical reaction.";
  466. defn[9]="The study of rate of reactions.";
  467. for(i=0;i<9;i++) {
  468. if(d.equals(name[i]))
  469. n=i; }
  470. out.println(defn[n]);
  471. %>
  472.  
  473. 5) To display the time
  474.  
  475. <html>
  476. <body>
  477. <script type="text/javascript">
  478. var d=new Date()
  479. document.write(d.getUTCHours())
  480. document.write(".")
  481. document.write(d.getUTCMinutes())
  482. document.write(".")
  483. document.write(d.getUTCSeconds())
  484. </script>
  485. </body>
  486. </html>
Add Comment
Please, Sign In to add comment