-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2d array & forms.php
130 lines (124 loc) · 3.55 KB
/
2d array & forms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<html>
<body>
<h1>2 dimensinonal Array</h1>
<?php
$car = array(array("Tata",1990,34),
array("volvo",2005,19),
array("mg",2018,6),
array("honda",2014,10));
for($row=0; $row<4;$row++){
echo"<p><b>Row number $row</p></b>";
echo "<ul>";
for($col =0; $col<3;$col++){
echo "<li>".$car[$row][$col]."</li>";
}
echo "</ul>";
}
$x=4;
echo $x,"<br>";
$x++;
echo $x."<br>";
$x--;
echo $x;
echo "<br>";
$y = 1;
while($y <=10){
if($y==3){
break;
}
echo "the number is:".$y."<br>";
$y++;
}
echo "<br>";
$a=1;
do {
echo $a."<br>";
$a++;
} while ($a <= 10);
echo "<br>";
$b=array ("name"=> "Aakash", "age"=>24, "year"=>2000);
foreach ($b as $c=>$d){
echo "$c:$d.<br>";
}
echo "<br>";
function myfamily($fname,$age){
echo "my name is ".$fname." i am ".$age." old."."<br>";
}
myfamily("Aakash",24);
myfamily("Aadarsh",14);
echo "<br>";
function average ($x ,$y){
$average = ($x+$y)/2;
echo "the average of number is :".$average."<br>";
// echo "the average of number is :".($x+ $y)/2 ."<br>";
}
echo average(4,6);
echo average(8,4);
echo "<br>";
function area_squre($a){
$area = $a*$a;
return $area."<br>";
}
echo area_squre(5);
echo area_squre(8);
echo "<br>";
?>
<html>
<body>
<!-- <form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
PASSWORD: <input type="password" name="password"><br>
Comment :<textarea type="Comment" rows="10" cols="50" ></textarea>
<input type="submit">
<br> -->
<?php
// define variables and set to empty values
$name = $email = $gender = $comment = $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = test_input($_POST["name"]);
$email = test_input($_POST["email"]);
$website = test_input($_POST["website"]);
$comment = test_input($_POST["comment"]);
$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>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
Gender:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="other">Other
<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;
?>
<br><br>
</form>
</body>
</html>