· 9 years ago · May 05, 2017, 06:14 AM
1NEW QUESTIONS
2
3for calculator.php
4<html>
5 <head>
6 <title>CALCULATOR USING PHP</title>
7 <style type="text/css"> /*ADDING BACKGROUNG COLOUR ANS SETTINGS*/
8 body{
9 background-color: #d2b48c;
10 margin-left: 20%;
11 margin-right:20%;
12 border: 1px dotted gray;
13 font-family: sans-serif;
14 }
15 </style>
16
17 <head>
18 <body>
19
20 <center></br></br>
21
22 <form name="frm" action="form1.php" method="post">
23 Enter Value:
24 <input type="text" name="first" value= "<?php echo $_REQUEST['number'];
25 echo $_REQUEST['calculate'];echo $_REQUEST['result']; ?>"> </br></br>
26 </from>
27
28
29 <form name="frm" action="form1.php" method="post">
30 <input type="submit" name="number" value="1">
31 </from>
32
33 <form name="frm" action="form1.php" method="post">
34 <input type="submit" name="number" value="2">
35 </from>
36
37 <form name="frm" action="form1.php" method="post">
38 <input type="submit" name="number" value="3"></br></br>
39 </from>
40 <form name="frm" action="form1.php" method="post">
41 <input type="submit" name="number" value="4">
42 </from>
43
44 <form name="frm" action="form1.php" method="post">
45 <input type="submit" name="number" value="5">
46 </from>
47
48 <form name="frm" action="form1.php" method="post">
49 <input type="submit" name="number" value="6"></br></br>
50 </from>
51
52 <form name="frm" action="form1.php" method="post">
53 <input type="submit" name="number" value="7">
54 </from>
55
56 <form name="frm" action="form1.php" method="post">
57 <input type="submit" name="number" value="8">
58 </from>
59
60
61 <form name="frm" action="form1.php" method="post">
62 <input type="submit" name="number" value="9"></br></br>
63 </from>
64
65 <form name="frm" action="form1.php" method="post">
66 <input type="submit" name="calculate" value="+">
67 </from>
68
69 <form name="frm" action="form1.php" method="post">
70 <input type="submit" name="calculate" value="0">
71 </from>
72
73 <form name="frm" action="form1.php" method="post">
74 <input type="submit" name="calculate" value="*"></br></br>
75 </from>
76 <form name="frm" action="form1.php" method="post">
77 <input type="submit" name="calculate" value="/">
78 </from>
79
80
81 <form name="frm" action="form1.php" method="post">
82 <input type="submit" name="calculate" value="-"></br></br>
83 </form>
84
85 <form name="frm" action="form1.php" method="post">
86 <input type="submit" value="=" name="result">
87
88 </form>
89
90 </center>
91 </body>
92 </html>
93
94
95 for form1.php
96
97
98
99
100
101<html>
102
103<head>
104
105<title></title>
106
107</head>
108
109<body>
110
111
112
113<?php
114
115
116
117
118
119 if(isset($_POST['result']))
120
121 {
122
123 include "at.php";
124
125 $oper=$_POST['calculate'];
126
127
128
129 if($_oper == '+')
130
131 {
132
133 echo "+";
134
135 $oper='+';
136
137 $result=$_POST['number']+10;
138
139 echo $result;
140
141
142
143 }
144
145 else if($oper == '-')
146
147 {
148
149 echo "-";
150
151 $oper='-';
152
153 $result=$_POST['number']-10;
154
155 echo $result;
156
157
158
159 }
160
161 else if($_POST['calculate'] == '/' )
162
163 {
164
165 echo "/";
166
167 $oper='/';
168
169 $result=$_POST['number']/10;
170
171 echo $result;
172
173
174
175 }
176
177 else
178
179
180
181 {
182
183 echo "*";
184
185 $oper='*';
186
187 $result=$_POST['number']*10;
188
189 echo $result;
190
191 }
192
193 }
194
195
196
197
198
199 if(isset($_POST['number']))
200
201 {
202
203
204 include "at.php";
205
206 $var=$_POST['number'];
207
208
209
210 echo "</br>";
211
212 echo $var;
213
214 echo "Enter the operator";
215
216 }
217
218
219
220 if(isset($_POST['calculate']))
221
222 {
223
224 include "at.php";
225
226 $oper=$_POST['calculate'];
227
228
229
230 echo $_POST['calculate'];
231
232 echo "</br>";
233
234
235
236 }
237
238
239
240
241
242 ?>
243
244
245
246</body>
247
248</html>
249
250
251//fibonacci while loop
252
253<?php
254$count = 0 ;
255$f1 = 0;
256$f2 = 1;
257echo $f1." , ";
258echo $f2." , ";
259while ($count < 20 )
260{
261$f3 = $f2 + $f1 ;
262echo $f3." , ";
263$f1 = $f2 ;
264$f2 = $f3 ;
265$count = $count + 1;
266}
267?>
268
269///prime nos in php upto 20
270<?php
271$count = 0 ;
272$number = 2 ;
273while ($count < 20 )
274{
275$div_count=0;
276for ( $i=1;$i<=$number;$i++)
277{
278if (($number%$i)==0)
279{
280$div_count++;
281}
282}
283if ($div_count<3)
284{
285echo $number." , ";
286$count=$count+1;
287}
288$number=$number+1;
289}
290?>
291
292//file upload
293
294<form action="upload.php" method="post" enctype="multipart/form-data">
295<input type="file" name="fileupload" id="file" />
296<input type="submit" name="submit" value="Upload file" />
297</form>
298
299//fread
300<?php
301// First we will create a file syam.txt and write a string into that
302$file = fopen("syam.txt","w");
303fwrite($file,"Here You can learn about how to write to a file");
304fclose($file);
305// Now we are going to read the contents of the created file and display the contents
306$file_1 = fopen("syam.txt","r");
307$data=fread($file_1,filesize("syam.txt"));
308echo $data;
309fclose($file_1);
310?>
311
312//fwrite
313<?php
314$file = fopen("syam.txt","w");
315fwrite($file,"Here You can learn about how to write to a file");
316fclose($file);
317?>
318
319//fopen
320$file=fopen(“syam.txtâ€,â€râ€);
321See the different opening modes used with fopen()
322
323r : Open for read only, Start from the beginning of file
324r+ : open for read and write , start from the beginning of file
325w : Open for write only, if the file exists all the data will be removed and start from the beginning, if the file not exist – it will create the new file
326w+ : Open for write and read, if the file exists all the data will be removed and start from the beginning, if the file not exist – it will create the new file
327a : Open for write only , mainly for append operation, will point to the end of file , will create a new file if file not exist
328a+ : Open for read and write, will point to the end of file , will create a new file if file not exist
329x : create and open for write only , starts from the beginning of file, if the file exist E_WARNING error will occur, if the file does not exist it will create a new file
330x+ : create and open for read and write, starts from the beginning of file, if the file exist E_WARNING error will occur, if the file does not exist it will create a new file
331
332//calculator in javascript
333
334<html>
335<head></head>
336<body>
337<h3>Simple Calculator</h3>
338<br/>
339<style>
340#calc{width:300px;height:250px;}
341#btn{width:100%;height:40px;font-size:20px;}
342</style>
343<form Name="calc">
344<table id="calc" border=2>
345<tr>
346<td colspan=5><input id="btn" name="display" onkeypress="return event.charCode >= 48 && event.charCode <= 57" type="text"></td>
347<td style="display:none"><input name="M" type="number"></td>
348</tr>
349<tr>
350<td><input id="btn" type=button value="MC" OnClick="calc.M.value=''"></td>
351<td><input id="btn" type=button value="0" OnClick="calc.display.value+='0'"></td>
352<td><input id="btn" type=button value="1" OnClick="calc.display.value+='1'"></td>
353<td><input id="btn" type=button value="2" OnClick="calc.display.value+='2'"></td>
354<td><input id="btn" type=button value="+" OnClick="calc.display.value+='+'"></td>
355</tr>
356<tr>
357<td><input id="btn" type=button value="MS" OnClick="calc.M.value=calc.display.value"></td>
358<td><input id="btn" type=button value="3" OnClick="calc.display.value+='3'"></td>
359<td><input id="btn" type=button value="4" OnClick="calc.display.value+='4'"></td>
360<td><input id="btn" type=button value="5" OnClick="calc.display.value+='5'"></td>
361<td><input id="btn" type=button value="-" OnClick="calc.display.value+='-'"></td>
362</tr>
363<tr>
364<td><input id="btn" type=button value="MR" OnClick="calc.display.value=calc.M.value"></td>
365<td><input id="btn" type=button value="6" OnClick="calc.display.value+='6'"></td>
366<td><input id="btn" type=button value="7" OnClick="calc.display.value+='7'"></td>
367<td><input id="btn" type=button value="8" OnClick="calc.display.value+='8'"></td>
368<td><input id="btn" type=button value="x" OnClick="calc.display.value+='*'"></td>
369</tr>
370<tr>
371<td><input id="btn" type=button value="M+" OnClick="calc.M.value=(Number(calc.M.value))+(Number(calc.display.value))"></td>
372<td><input id="btn" type=button value="9" OnClick="calc.display.value+='9'"></td>
373<td><input id="btn" type=button value="±"
374
375OnClick="calc.display.value=(calc.display.value==Math.abs(calc.display.value)?-(calc.display.value):Math.abs(calc.display.value))">
376
377</td>
378<td><input id="btn" type=button value="=" OnClick="calc.display.value=eval(calc.display.value)"></td>
379<td><input id="btn" type=button value="/" OnClick="calc.display.value+='/'"></td>
380</tr>
381<tr>
382<td><input id="btn" type=button value="1/x" OnClick="calc.display.value=1/calc.display.value"></td>
383<td><input id="btn" type=button value="." OnClick="calc.display.value+='.'"></td>
384<td><input id="btn" type=button value="x2" OnClick="calc.display.value=Math.pow(calc.display.value,2)"></td>
385<td><input id="btn" type=button value="√" OnClick="calc.display.value=Math.sqrt(calc.display.value)"></td>
386<td><input id="btn" type=button value="C" OnClick="calc.display.value=''"></td>
387</tr>
388</table>
389</form>
390</body>
391</html>
392
393//fibonacci with for loop
394<?php
395
396function printFibonacci($n)
397 {
398
399 $first = 0;
400 $second = 1;
401
402 echo "Fibonacci Series \n";
403
404 echo $first.' '.$second.' ';
405
406 for($i = 2; $i < $n; $i++){
407
408 $third = $first + $second;
409
410 echo $third.' ';
411
412 $first = $second;
413 $second = $third;
414
415 }
416}
417
418/* Function call to print Fibonacci series upto 6 numbers. */
419
420printFibonacci(6);
421
422?>
423//javascript digital clock
424<!DOCTYPE html>
425<html>
426<head>
427<script>
428function startTime() {
429 var today = new Date();
430 var h = today.getHours();
431 var m = today.getMinutes();
432 var s = today.getSeconds();
433 m = checkTime(m);
434 s = checkTime(s);
435 document.getElementById('txt').innerHTML =
436 h + ":" + m + ":" + s;
437 var t = setTimeout(startTime, 500);
438}
439function checkTime(i) {
440 if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
441 return i;
442}
443</script>
444</head>
445
446<body onload="startTime()">
447
448<div id="txt"></div>
449
450</body>
451</html>
452
453// digital clock
454
455function startTime() {
456 var today = new Date();
457 var hr = today.getHours();
458 var min = today.getMinutes();
459 var sec = today.getSeconds();
460 //Add a zero in front of numbers<10
461 min = checkTime(min);
462 sec = checkTime(sec);
463 document.getElementById("clock").innerHTML = hr + " : " + min + " : " + sec;
464 var time = setTimeout(function(){ startTime() }, 500);
465}
466function checkTime(i) {
467 if (i < 10) {
468 i = "0" + i;
469 }
470 return i;
471}
472
473///php digital clock
474<?php
475date_default_timezone_set('UTC');
476?>
477<script>
478var d = new Date(<?php echo time() * 1000 ?>);
479function digitalClock() {
480 d.setTime(d.getTime() + 1000);
481 var hrs = d.getHours();
482 var mins = d.getMinutes();
483 var secs = d.getSeconds();
484 mins = (mins < 10 ? "0" : "") + mins;
485 secs = (secs < 10 ? "0" : "") + secs;
486 var apm = (hrs < 12) ? "am" : "pm";
487 hrs = (hrs > 12) ? hrs - 12 : hrs;
488 hrs = (hrs == 0) ? 12 : hrs;
489 var ctime = hrs + ":" + mins + ":" + secs + " " + apm;
490 document.getElementById("clock").firstChild.nodeValue = ctime;
491}
492window.onload = function() {
493 digitalClock();
494 setInterval('digitalClock()', 1000);
495}
496</script>
497<div id="clock"> </div>
498
499//date clock
500
501<?php
502// Prints the day
503echo date("l") . "<br>";
504
505// Prints the day, date, month, year, time, AM or PM
506echo date("l jS \of F Y h:i:s A");
507?>
508
509
510
511// follow.php
512
513<html>
514<head>
515</head>
516<body>
517</body>
518</html>
519<?php
520$servername = "localhost";
521$username = "root";
522$password = "";
523
524// Create connection
525$conn1 = new mysqli($servername, $username, $password,"feed_db");
526
527// Check connection
528if ($conn1->connect_error) {
529 die("Connection failed: " . $conn1->connect_error);
530}
531echo "Connected successfully";
532$name=$_POST['name1'];
533$email=$_POST['email1'];
534$bool=true;
535$query=mysqli_query("Select * from follower");
536while($row=mysqli_fetch_array($conn1,$query))
537{
538$table_users=$row['email'];
539if($email==$table_users)
540{
541$bool=false;
542Print '<script>alert("User Email alread exists!");</script>';
543Print '<script>window.location.assign("index.php");</script>';
544}
545}
546if($bool)
547{
548$sql="INSERT INTO follower(name,email) VALUES ('$name','$email')";
549if(mysqli_query($conn1,$sql))
550{
551 echo "Records inserted successfully.";
552 Print '<script>window.location.assign("index.php");</script>';
553} else
554{
555 echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn1);
556}
557
558}
559$conn1->close();
560?>
561
562/// validate()
563
564<script>
565function validate()
566 {
567 var phoneno=document.getElementById("phoneno");
568 var name1=document.getElementById("name1");
569 var email=document.getElementById("email");
570 var feedback=document.getElementById("feedback");
571if(phoneno.value.length!=10)
572 {
573window.alert("Mobile Number Should Be Exactly 10 Digits");
574}
575var a = document.form1.name1.value;
576if(a=="")
577{
578alert("Please Enter Your Name");
579document.form1.name1.focus();
580return false;
581}
582if(!isNaN(a))
583{
584alert("Please Enter Only Characters");
585document.form1.name1.select();
586return false;
587}
588
589
590if((email.value.search(/^[a-z][0-9]*[@][a-z]*[.][a-z]*$/g)!=-1)||(email.value.split(".").length<=1))
591 { window.alert("Enter correct email"); }
592 }
593 if((feedback.value)==null)
594 {
595 window.alert("Required Field");
596 }
597
598 function goBack() {
599 window.history.back();
600 }
601 </script>
602
603 //form
604 <table cellspacing="3px">
605 <tr>
606 <form name="form1" id="form1" onSubmit="validate()" method="POST" action="feed.php">
607 <tr>
608 <td>Name:</td>
609 <td><input name="name" id="name1" size="30" type="text" /></td>
610
611 </tr>
612 <tr>
613 <td>Email:</td>
614 <td><input name="email" id="email" size="30" type="text" /></td>
615
616 </tr>
617 <tr>
618 <td>Phone no:</td>
619 <td><input name="phoneno" id="phoneno" size="30" type="text" /></td>
620
621 </tr>
622 <tr>
623 <td>Ratings:</td>
624 <td><select name="point">
625 <option value="1">1</option>
626 <option value="2">2</option>
627 <option value="3">3</option>
628 <option value="4">4</option>
629 <option value="5" selected="selected">5</option>
630 </select></td>
631 </tr>
632 <tr>
633 <td>Feedback Comments:</td>
634 <td><textarea name="feedback" id="feedback" size="100" type="text" required="required"></textarea></td>
635
636 </tr>
637 </table>
638 <br/><center>
639 <p><input type="submit" name="submit" value="Enter" onclick="alert('Are You Sure')"/></p></center>
640 </form>
641
642 </div>
643
644 // validate
645
646 <script>
647
648function validate1()
649 {
650 var name=document.getElementById("name1");
651 var email=document.getElementById("email1");
652
653var a = document.contact.name1.value;
654if(a=="")
655{
656alert("Please Enter Your Name");
657document.contact.name1.focus();
658return false;
659}
660if(!isNaN(a))
661{
662alert("Please Enter Only Characters");
663document.contact.name1.select();
664return false;
665}
666
667if((email.value.search(/^[a-z][0-9]*[@][a-z]*[.][a-z]*$/g)!=-1)||(email.value.split(".").length<=1))
668 { window.alert("Enter correct email"); }
669 }
670
671 function goBack() {
672 window.history.back();
673 }
674
675</script>
676
677/// feed.php
678<?php
679$servername = "localhost";
680$username = "root";
681$password = "";
682
683// Create connection
684$conn1 = new mysqli($servername, $username, $password,"feed_db");
685
686// Check connection
687if ($conn1->connect_error) {
688 die("Connection failed: " . $conn1->connect_error);
689}
690echo "Connected successfully";
691
692$name = $email = $phone = $feedback ="";
693$name=$_POST['name'];
694$email=$_POST['email'];
695$phone=$_POST['phoneno'];
696$points=$_POST['point'];
697$feedback=$_POST['feedback'];
698$bool=true;
699$query=mysqli_query("Select * from readers");
700while($row=mysqli_fetch_array($conn1,$query))
701{
702$table_users=$row['email'];
703if($email==$table_users)
704{
705$bool=false;
706Print '<script>alert("User Email alread exists!");</script>';
707Print '<script>window.location.assign("index.php");</script>';
708}
709}
710if($bool)
711{
712$sql="INSERT INTO readers(name,email,phone,ratings,feedback) VALUES ('$name','$email','$phone','$points','$feedback')";
713if(mysqli_query($conn1,$sql))
714{
715 echo "Records inserted successfully.";
716 Print '<script>window.location.assign("index.php");</script>';
717} else
718{
719 echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn1);
720}
721
722}
723$conn1->close();
724?>
725
726/// css
727body {
728 margin: 0;
729 padding: 0;
730 color:#302d26;
731 font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
732 font-size: 18px;
733 line-height: 1.4em;
734 background-color:#a09c93;
735 background-image: url(images/2.jpg);
736 background-repeat: repeat-y;
737 background-position: center
738}
739
740a, a:link, a:visited { color: #840000; font-weight: normal; text-decoration: none }
741a:hover { text-decoration: underline; }
742
743a.gototop { clear: both; float: right; display:block; margin-top: 40px; padding: 0 15px 10px; font-size: 10px; color: #000; font-weight: 700;background: url(images/gototop.png) no-repeat bottom center }
744
745p { margin: 0 0 10px 0; padding: 0; }
746img { border: none; }
747em { color: #fff }
748blockquote { font-style: italic; margin: 0 0 20px 0}
749cite { font-weight: bold; color:#840000; }
750cite a, cite a:link, cite a:visited { font-size: 12px; text-decoration: none; font-style: normal }
751cite span { font-weight: 400; color: #302d26; }
752
753h1, h2, h3, h4, h5, h6 { color: #000000; font-weight: normal; }
754h1 { font-size: 36px; margin: 0 0 30px; padding: 5px 0 }
755h2 { font-size: 24px; margin: 0 0 25px; padding: 5px 0 }
756h3 { font-size: 20px; margin: 0 0 20px; padding: 0; }
757h4 { font-size: 16px; margin: 0 0 15px; padding: 0; }
758h5 { font-size: 14px; margin: 0 0 10px; padding: 0; }
759h6 { font-size: 12px; margin: 0 0 5px; padding: 0; font-weight: 700 }
760
761.cleaner { clear: both }
762.h10 { height: 10px }
763.h20 { height: 20px }
764.h30 { height: 30px }
765.h40 { height: 40px }
766.h50 { height: 50px }
767.divider { margin-bottom: 40px; padding-bottom: 20px; background: url(images/tooplate_divider.png) repeat-x bottom }
768
769.float_l { float: left }
770.float_r { float: right }
771
772
773.tooplate_list { margin: 10px 0 10px 30px; padding: 0; list-style: decimal-leading-zero }
774.tooplate_list li { color:#302d26; margin: 0 0 10px 0; padding: 0 5px 0 0; background: url(images/tooplate_list.png) no-repeat scroll 0 5px }
775.tooplate_list li a { color: #302d26; font-weight: normal }
776.tooplate_list li a:hover { color: #302d26 }
777
778#tooplate_wrapper {
779 width: 960px;
780 padding: 0 10px;
781 margin: 0 auto;
782}
783
784#tooplate_sidebar {
785 position: fixed;
786 width: 240px;
787 text-align: right;
788}
789
790#tooplate_main {
791 width: 650px;
792 padding: 60px 30px 60px 40px;
793 float: right;
794}