Skip to content

Commit 4e0877e

Browse files
committed
update notes
1 parent fa86482 commit 4e0877e

File tree

15 files changed

+347
-128
lines changed

15 files changed

+347
-128
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<a href="./tutorials/tut6/index.html">Tutorial 6 - JS DOM</a><br>
4444
<a href="./tutorials/tut7/index.html">Tutorial 7 - PHP</a><br>
4545
<a href="./tutorials/tut8/index.html">Tutorial 8 - PHP</a><br>
46-
<a href="./tutorials/tut9/website/">Tutorial 9 - Dynamic Website using PHP</a><br>
46+
<a href="./tutorials/tut9/website/">Tutorial 9 - Dynamic Website using PHP & MySQL</a><br>
4747
</p>
4848
</section>
4949
</div>

mod3/assoc_arr.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Items Array</title>
7+
</head>
8+
<body>
9+
<h1>Items Array</h1>
10+
<?php
11+
$items = array(
12+
'Bread' => 30,
13+
'Butter' => 30,
14+
'Jam' => 35,
15+
'Cheese' => 32
16+
);
17+
18+
echo "<b>Items Array :</b><br/>";
19+
foreach ($items as $product => $price) {
20+
echo "$product: $price <br/>";
21+
}
22+
echo "<br/>";
23+
24+
// asort($items);
25+
26+
// echo "<b>After Sorting (by values):</b><br/>";
27+
// foreach ($items as $product => $price) {
28+
// echo "$product: $price <br/>";
29+
// }
30+
?>
31+
</body>
32+
</html>

mod3/explode_implode_fn.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
print("1. Example for explode(): <br/><br/>");
3+
$str = "Apple, Banana, Orange, Grape";
4+
print("$str </br>");
5+
$arr = explode(", ", $str);
6+
print_r($arr);
7+
8+
print("<br/><br/>");
9+
10+
print("2. Example for implode(): <br/><br/>");
11+
// foreach ($str as $product => $price) {
12+
// echo "$product: $price <br/>";
13+
// }
14+
$arr = array("Apple", "Banana", "Orange", "Grape");
15+
// print("$arr </br>");
16+
$str = implode(", ", $arr);
17+
echo $str;
18+
19+
?>

mod3/index.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Document</title>
8+
<link rel="stylesheet" href="./assets/css/style.css">
89
</head>
910

1011
<body>
@@ -19,6 +20,7 @@
1920
<h2><br>Files</h2>
2021
<div>
2122
<ul>
23+
<!-- basics -->
2224
<li><a href="index.php">PHP HomePage</a></li>
2325
<li><a href="helloworld.php">PHP Hello</a></li>
2426
<li><a href="equal_op_rectangle.php">Equal Operator</a></li>
@@ -28,7 +30,18 @@
2830
<li><a href="randomNum.php">Random Number</a></li>
2931
<li><a href="constants.php">Constants</a></li>
3032
<li><a href="dateValue.php">Date</a></li>
33+
34+
<!-- flow control -->
35+
<li><a href="powers_table.php">Powers Table</a></li>
36+
37+
<!-- array -->
38+
<li><a href="assoc_arr.php">Associative Array</a></li>
39+
<li><a href="explode_implode_fn.php">explode_implode</a></li>
40+
41+
<!-- objects -->
3142
<li><a href="carobj.php">Class & Objects</a></li>
43+
44+
<!-- string -->
3245
<li><a href="PatternMatch.php">Pattern-Match</a></li>
3346
<li><a href="override.php">Method Overriding</a></li>
3447
<li><a href="strcmp.php">String Compare</a></li>

mod3/powers_table.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>powers table</title>
7+
</head>
8+
<body>
9+
<table border = "border">
10+
<caption><b>Powers Table</b></caption>
11+
<tr><th>Number</th><th>Root</th><th>Square</th><th>Cube</th><th>Quad</th></tr>
12+
<?php
13+
for ($num = 1; $num<=10; $num++) {
14+
$root = sqrt($num);
15+
$square = pow($num,2);
16+
$cube = pow($num,3);
17+
$quad = pow($num,4);
18+
19+
// print("$num, $root, $square, $cube, $quad<br/>");
20+
print("<tr align='center'><td>$num</td><td>$root</td><td>$square</td><td>$cube</td><td>$quad</td></tr>");
21+
}
22+
?>
23+
</table>
24+
</body>
25+
</html>
Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
1-
<!DOCTYPE html>
2-
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>Calculate</title>
8-
</head>
9-
<body>
10-
11-
<?php
12-
if(isset($_GET["operator"]))
13-
{
14-
$n1 = $_GET['num1'];
15-
$n2 = $_GET['num2'];
16-
$op = $_GET['operator'];
17-
$res = '';
18-
19-
if (is_numeric($n1) && is_numeric($n2)) {
20-
switch ($op) {
21-
case "Add":
22-
$res = $n1 + $n2;
23-
break;
24-
case "Sub":
25-
$res = $n1 - $n2;
26-
break;
27-
case "Mul":
28-
$res = $n1 * $n2;
29-
break;
30-
case "Div":
31-
$res = $n1 / $n2;
32-
break;
33-
}
34-
// echo "Result = " . $res;
35-
}
36-
}
37-
else{
38-
echo"Enter all values";
39-
}
40-
?>
41-
42-
<h1>Calculate</h1>
43-
<form method ="get">
44-
Number 1: <input type="number" name="num1" id="mum1" required value="<?php echo $n1; ?>"/>
45-
<br/><br/>
46-
Number 2: <input type="number" name="num2" id="mum2" required value="<?php echo $n2; ?>"/>
47-
<br/><br/>
48-
<input type="submit" name="operator" value="Add"/>
49-
<input type="submit" name="operator" value="Sub"/>
50-
<input type="submit" name="operator" value="Mul"/>
51-
<input type="submit" name="operator" value="Div"/>
52-
<br/><br/>
53-
Result : <?php echo $res; ?>
54-
<br/><br/>
55-
</form>
56-
57-
</body>
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Calculate</title>
8+
</head>
9+
<body>
10+
11+
<?php
12+
if(isset($_GET["operator"]))
13+
{
14+
$n1 = $_GET['num1'];
15+
$n2 = $_GET['num2'];
16+
$op = $_GET['operator'];
17+
$res = '';
18+
19+
if (is_numeric($n1) && is_numeric($n2)) {
20+
switch ($op) {
21+
case "Add":
22+
$res = $n1 + $n2;
23+
break;
24+
case "Sub":
25+
$res = $n1 - $n2;
26+
break;
27+
case "Mul":
28+
$res = $n1 * $n2;
29+
break;
30+
case "Div":
31+
$res = $n1 / $n2;
32+
break;
33+
}
34+
// echo "Result = " . $res;
35+
}
36+
}
37+
else{
38+
echo"Enter all values";
39+
}
40+
?>
41+
42+
<h1>Calculate</h1>
43+
<form method ="get">
44+
Number 1: <input type="number" name="num1" id="mum1" required value="<?php echo $n1; ?>"/>
45+
<br/><br/>
46+
Number 2: <input type="number" name="num2" id="mum2" required value="<?php echo $n2; ?>"/>
47+
<br/><br/>
48+
<input type="submit" name="operator" value="Add"/>
49+
<input type="submit" name="operator" value="Sub"/>
50+
<input type="submit" name="operator" value="Mul"/>
51+
<input type="submit" name="operator" value="Div"/>
52+
<br/><br/>
53+
Result : <?php echo $res; ?>
54+
<br/><br/>
55+
</form>
56+
57+
</body>
5858
</html>

mod4/cookie.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
$cookie_name = "user";
3+
$cookie_val = "admin123";
4+
setcookie($cookie_name, $cookie_val, time()+5, "/");
5+
?>
6+
<!DOCTYPE html>
7+
<html lang="en">
8+
<head>
9+
<meta charset="UTF-8">
10+
<meta name="viewport" content="width=device-width, initial-scale=1.0">.
11+
<title>Cookies</title>
12+
</head>
13+
<body>
14+
<?php
15+
if(!isset($_COOKIE[$cookie_name])) {
16+
echo "Cookie named " .$cookie_name . " is not set!";
17+
}
18+
else {
19+
echo "Cookie named " .$cookie_name . " is set!<br/>";
20+
echo "Value is " . $_COOKIE[$cookie_name];
21+
}
22+
?>
23+
</body>
24+
</html>

mod4/index.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,18 @@
1919
<h2><br>Files</h2>
2020
<div>
2121
<ul>
22+
<!-- Form Processing -->
23+
<li><a href="calculate.php">Calculator</a></li>
24+
25+
<!-- Cookies & Sessions -->
26+
<li><a href="cookie.php">Cookies</a></li>
27+
<li><a href="savecookie.php">Write Cookies</a></li>
28+
<li><a href="testlogin.php">Session</a></li>
29+
30+
<!-- MySQL -->
2231
<li><a href="conn_test.php">Connection</a></li>
23-
<li>Run <a href="testinsert.php">Insert into table</a> using <a href="testform.html">HTML form</a></li>
24-
<li><a href="insert2.php">insert 2</a></li>
32+
<li>Run <a href="testinsert.php">Insert into table</a> using <a href="testform1.html">HTML form 1</a></li>
33+
<li><a href="insert2.php">insert 2</a> using <a href="testform2.html">HTML form 2</a></li>
2534
<li><a href="tablecreate.php">create table</a></li>
2635
<li><a href="update.php">update</a></li>
2736
<li><a href="fetchdata.php">Display data in table</a></li>

mod4/savecookie.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
if (isset($_POST["submit"])) {
3+
setcookie("name",$_POST["uname"],time()+500);
4+
setcookie("colour",$_POST["clr"],time()+500);
5+
$name = $_COOKIE["name"];
6+
$colour = $_COOKIE["colour"];
7+
echo "Cookies set :<br/>";
8+
echo "Name : $name <br/> Colour : $colour <br/> ";
9+
}
10+
else{
11+
?>
12+
<!DOCTYPE html>
13+
<html lang="en">
14+
<head>
15+
<meta charset="UTF-8">
16+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
17+
<title>Document</title>
18+
</head>
19+
<body>
20+
<form action="savecookie.php" method="post">
21+
Enter Name :
22+
<input type="text" name="uname" />
23+
<br/><br/>
24+
Enter Colour :
25+
<input type="text" name="clr" />
26+
<br/><br/>
27+
<input type="submit" name="submit" value="Set Cookie" />
28+
</form>
29+
</body>
30+
</html>
31+
<?php
32+
}
33+
?>

mod4/testform1.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Form</title>
7+
</head>
8+
<body>
9+
<form action="testinsert.php" method="post">
10+
<p>Enter Text to add:
11+
<input type="text" name="testfield" size="30" />
12+
</p>
13+
<input type="submit" name="submit" value="insert record" />
14+
</form>
15+
</body>
16+
</html>

0 commit comments

Comments
 (0)