Web Technologies Fat Exam Codes
Web Technologies Fat Exam Codes
$allowedExtensions = [
'application/pdf',
'application/msword',
'text/plain',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
];
if(isset($_FILES['upfile'])){
$errors= array();
$file_name = $_FILES['upfile']['name'];
$file_size =$_FILES['upfile']['size'];
$file_tmp =$_FILES['upfile']['tmp_name'];
$file_type=$_FILES['upfile']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['upfile']['name'])));
}
if($file_size > 100000){
if(empty($errors)==true){
move_uploaded_file($file_tmp,"test/".$file_name);
echo "Success";
}else{
print_r($errors);
?>
<html>
<body>
<input type="submit"/>
</form>
</body>
</html>
Code:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta content="width=device-width, initial-scale=1, name="viewport">
<script type="text/javascript">
function myValidation()
{
var p = document.getElementById('username').value;
if (!checkUsername(p))
{
alert('User name validation rules have not matched!');
alert('Not Completed');
return false;
}
if (!PhoneCheck(phone))
{
alert('The Phone should have exactly 10 digits');
return false;
}
alert('up. Form ready for submit.');
}
function PhoneCheck(pas)
{
var theRegexForUs = /^(\d){10}$/;
return theRegexForUs.test(pas);
}
}
else
{
return false;
}
}
function checkUsername(username) {
// first character should be a letter
if (!username.match(/^[a-z]+$/i))
{
alert('The Username must not have anything other than Alphanumeric
characters!');
return false;
}
return true;
}
</script>
<title>Registration</title>
<!--<link rel="stylesheet" type="text/css" href="../css/post_style.css">-->
</head>
<body>
<header>
<!--Must have a section heading introducing the form-->
<h1>Registration Form</h1>
</header>
<form name="myForm" onsubmit="return myValidation();" method="post">
<div>
<!--Must ask user to input a username-->
<label for="uname">Username</label>
<input type="text" id="username" name="uname" required
placeholder="Username:"/>
</div>
<br/><br/>
<div>
<label for="pass">Password</label>
<input type="password" id="pass" name="password" required/>
</div>
<div>
<!--Must ask user to input a confirm password-->
<br/><br/>
<label for="repass">Confirm Password</label>
<input type="password" id="repass" name="repass" required/>
</div>
<div>
<!--Must ask user to input a confirm password-->
<br/><br/>
<label for="phone">Phone</label>
<input type="phone" id="phone" name="phone" required/>
</div>
<div>
<br/><br/>
<!--Must ask user to input an email.-->
<label for="email">Email Address</label>
<input type="email" id="em" name="em" required
placeholder="[email protected]"/>
</div>
<br/><br/>
<!--Must ask user to input a password-->
<!--Password input must be correct input type
(i.e. when I type I should not see the
password)-->
<input type="submit" method="post" name="action" value="Submit"/>
<button type="button" value="Reset"
onClick="window.location.reload();">Reset</button>
<!--<input type="reset" value="Reset">-->
</div>
</form>
</body>
</html>
As per the problem statement, we need to implement the conditions given below. I've
mentioned all the functions that help us implement those condition.
1. Validate username (username should not contain numbers and special symbols)
var p = document.getElementById('username').value;
if (!checkUsername(p))
{
alert('User name validation rules have not matched!');
alert('Not Completed');
return false;
}
////////
function checkUsername(username) {
// first character should be a letter
if (!username.match(/^[a-z]+$/i))
{
alert('The Username must not have anything other than Alphanumeric
characters!');
return false;
}
return true;
}
2. Password and confirm password boxes should contain same characters, letters and
symbols,
if the data in both the boxes are different, it should display the information.
}
else
{
return false;
}
}
3. Phone number field should contain only ten digits.
if (!PhoneCheck(phone))
{
alert('The Phone should have exactly 10 digits');
return false;
}
///////
function PhoneCheck(pas)
{
var theRegexForUs = /^(\d){10}$/;
return theRegexForUs.test(pas);
}
$result = $db->query($q)->fetchall()
echo $user['name']
};{;;
pageEncoding="ISO-8859-1"%
<html
<head
<title>Practical Work</title
</head
<body
<%
if(msg==null
out.println("\t")
els
out.println(msg)
<form action="login"
</body
</html>>>>>>>;e;) >>>>>>>>
<h2>DJ Access</h2
<div class="lineSpacer"></div
<div class="lineSpacer"></div
</form
<?php if($error){ ?
<?php } ?>>>>>>>>>>
4. Use AngularJS to create two controllers fruits and vegetables
consisting of fruitnames, vegnames arrays respectively. The
application should consist of,
a. Create two textboxes AddFruit and AddVeg to read values.
b. Create “Add” buttons with respect to two text boxes, on clicking
the buttons the arrays have to be updated.
C. Create “view” buttons to display the list of items in the array, use
filters to display the items in ascending order on the webpage.
Code:-
Fruitsveggies.js code:-
var app = angular.module
("application", []);
app.controller("fruits", function
($scope.fruitnames = ["orange","banana"];
$scope.addItem = function () {
if (!$scope.addMe) {
return;
}
if ($scope.fruitnames.indexof ($scope.addMe) == -1) {
$scope.fruitnames.push
($scope.addMe);
} else {
alert("Already added");
}
};
$scope.viewItem = function () {
$scope.fruitnames = $filter
("orderBy")($scope.fruitnames);
};
});
/*app.controller("vegetables",
function ($scope, $filter) {
$scope.vegnames = ["Tomato", "Brinjal"];
$scope.addItem2 = function() {
if (!&scope.addMe2) {
return;
}
if ($scope.vegnames.indexOf
($scope.vegnames.push
($scope.addMe2);
} else {
alert("Already added");
}
};
$scope.viewItem2 = function () {
$scope.vegnames = $filter
("orderBy")($scope.vegnames);
};
});*/
.js code:-
(or)
webpage.
<!DOCTYPE html>
<html ng-app="fruitsveg">
<head>
<title>AngularJS Controllers</title>
</head>
<body ng-controller="fruitsveg">
<!-- The controller containing the Fruit and Vegetable names. -->
<div ng-controller="fruits">
<table>
<tr>
<th>Name</th> <th>Price</th>
</td>
<table>
<tr>
<th>Name</th> <th>Price</th>
</td>
</input> </body>
</html> The above code will give below screen on the screen;
If we observe the HTML code above, it is a simple application consisting of two textboxes,
two buttons and one table to display the fruits and vegetables. We have two controllers
named as fruits and veg to control the operations in these components. The body tag has a
tag with controller as fruits and veg respectively. This tag with controller contains the two
text boxes
<tr>
<th>Name</th>
<th>Price</th>
The above code snippet shows that, we have two such tags in HTML body element. Both
these tags are inside of the tag with controller name fruits. The first tag is for the fruit
names and the second for the vegetable names, both these tags have tr element as child.
<input type="button" value="Add Fruits" onclick="addFruit()"> <input type="button"
value="Add Vegetables" onclick="addVeg()"> within this two textboxes which are called
AddFruit and AddVeg respectively. We have also two buttons in our code named as add
fruits and add vegetables. The code input button shows that, when it is clicked, a function
named addFruit will be called. On clicking the button addVeg, a function named addVeg will
be called respectively in our application.
5..Write a HTML code to create a form that contain three textboxes,
one submits button and clear button. Three textboxes should contain
A value(A), B value(B) and C value(c), respectively. On clicking the
submit button, the external JavaScript file should calculate the D and
display it using<h6> tag (font color should be yellow and background
color should be green). On clicking clear button, content in all the
textboxes and existing D value should be cleared. The mathematical
formula to calculate D is: D=2A+2B+2C.
Code:-
Code:-
CREATE TABLE `countries` ( `id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1=Active | 0=Inactive',
PRIMARY KEY (`id`))
CREATE TABLE `states` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`country_id` int(11) NOT NULL,
`name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1=Active | 0=Inactive',
PRIMARY KEY (`id`)
)
CREATE TABLE `cities` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`state_id` int(11) NOT NULL,
`name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1=Active | 0=Inactive',
PRIMARY KEY (`id`)
)
<?php
$servername='localhost';
$username='root';
$password='';
$dbname = "my_db";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
die('Could not Connect MySql Server:' .mysql_error());
}
?>
Index.php
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
</head>
<body>
<div class="card-body">
<form>
<div class="form-group">
<label for="country">Country</label>
<select class="form-control" id="country-dropdown">
<option value="">Select Country</option>
<?php
require_once "db.php";
$result = mysqli_query($conn,"SELECT * FROM countries");
while($row = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $row['id'];?>"><?php echo $row["name"];?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label for="state">State</label>
<select class="form-control" id="state-dropdown">
</select>
</div>
<div class="form-group">
<label for="city">City</label>
<select class="form-control" id="city-dropdown">
</select>
</div>
</div>
<script>
$(document).ready(function() {
$('#country-dropdown').on('change', function() {
var country_id = this.value;
$.ajax({
url: "states-by-country.php",
type: "POST",
data: { country_id: country_id },
cache: false,
success: function(result){
$("#state-dropdown").html(result);
$('#city-dropdown').html('<option value="">Select State First</option>');
}
}); });
$('#state-dropdown').on('change', function() {
var state_id = this.value;
$.ajax({
url: "cities-by-state.php",
type: "POST",
data: {
state_id: state_id
},
cache: false,
success: function(result){
$("#city-dropdown").html(result);
}
});}); });
</script>
</body>
</html>
states-by-country.php
<?php
require_once "db.php";
$country_id = $_POST["country_id"];
$result = mysqli_query($conn,"SELECT * FROM states where country_id = $country_id");
?>
<option value="">Select State</option>
<?php
while($row = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $row["id"];?>"><?php echo $row["name"];?></option>
<?php
}
cities-by-state.php
<?php
require_once "db.php";
$state_id = $_POST["state_id"];
$result = mysqli_query($conn,"SELECT * FROM cities where state_id = $state_id");
?>
<option value="">Select City</option>
<?php
while($row = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $row["id"];?>"><?php echo $row["name"];?></option>
<?php
}
?>