Question One Codes
Question One Codes
Write an HTML page that contains a selection box with a list of 5 countries. When the user
selects a country; its capital should be printed next in the list. Add CSS to customize the
properties of the font of the capital (color, bold and font size). Below is a list of countries and
their capital cities to add and the expected output. [20 marks].
Solution
<html>
<head>
<title>capitals of countries</title>
<style>
p{
color: blue;
font-weight: bold;
font-size: 50;
}
</style>
<script language="javascript">
function capital() {
var cunt = document.forms["P5"].country.value;
var capital = " Please select any country ";
if (cunt == "zimbabwe") {
capital = "Harare";
}
if (cunt == "zambia") {
capital = "Lusaka";
}
if (cunt == "mozambique") {
capital = "Maputo";
}
if (cunt == "botswana") {
capital = "Gaborone";
}
if (cunt == "swaziland") {
capital = "Mbabane";
}
if (cunt == "select") {
capital = "Please select any country";
}
document.getElementById("capt").innerHTML = capital;
}
</script>
</head>
<body>
<form name="P5">
<br/>
<center>
<h1 style="color: red;">Select the country name to find it's capital</h1>
Select a country: <select name="country">
<option value="select">--SELECT--</option>
<option value="zimbabwe">Zimbabwe</option>
<option value="zambia">Zambia</option>
<option value="mozambique">Mozambique</option>
<option value="botswana">Botswana</option>
<option value="swaziland">Swaziland</option>
</select>
</center>
<br/>
<br/>
<!-- <button class="button button1" type="button" onlick="alert('submitted
successfully')">submit</button> -->
<h3>Click on the below Submit Button</h3>
<h3 style="display:inline-block;">
<font color="black" size="4">Capital is :</font>
</h3>
<p id="capt"></p>
<!-- <button type="button" onclick="my_button_click_handler">Click this button</button>
-->
<!-- <script>
function my_button_click_handler()
{
alert('Button Clicked');
}
</script>
<br>
<br>
<font color="green" size="10">Capital is :</font> <p id="capt"></p> -->
</center>
</form>
</body>
</html>
Question Two
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method='GET'>
<h2>Please input your length:</h2>
<h2>Please input your width:</h2>
<input type="text" length="length">
<input type="text" width="width">
<input type="submit" value="Submit Name">
</form>
<?php
//Retrieve name from query string and store to a local variable
$name = $_GET['AREA'];
echo "<h3> Hello $AREA </h3>";
?>
</body>
</html>
Question3:
Develop an HTML program that includes JavaScript script to display a working digital
clock.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Digital Clock Using JavaScript </title>
<body>
<script src="script.js">
</script>
</body>
</html>
function Time() {
// Variable to store AM / PM
var period = "";
Time();
Question 4:
Design a PHP based web application that takes name and age from an HTML page. If the
age is less than 18, it should send a page with “Hello <name>, you are not authorized to
visit the site” message, where <name> should be replaced with the entered name.
Otherwise it should send “Welcome <name> to this site”
<?php
/* ------------ Sessions ------------ */
/*
Sessions are a way to store information (in variables) to be used across
multiple pages.
Unlike cookies, sessions are stored on the server.
*/
$age = 18;
session_start(); // Must be called before accessing any session data
if (isset($_POST['submit'])) {
$username = filter_input(
INPUT_POST,
'username',
FILTER_SANITIZE_FULL_SPECIAL_CHARS
);
$age = filter_input(
INPUT_POST,
'age',
FILTER_SANITIZE_FULL_SPECIAL_CHARS
);
<?php
session_start();
if (isset($_SESSION['username'])) {
echo '<h1>Welcome, ' . $_SESSION['username'] . '</h1>';
echo '<a href="logout.php">Logout</a>';
} else {
echo '<h1>Welcome, Guest</h1>';
echo '<a href="/PHP-crash/13_sessions.php">Home</a>'; //this is the dashboard
Php code…
}
<?php
session_start();
brad
Sara
Mike
The above are users..
Question5:
Assuming that a database called demo has already been created using MySQL. Write HTML
code for the form below and add php code to achieve the following:
i. Attempt MySQL server connection assuming you are running MySQL server with
default setting (user 'root' with no password)
ii. Check connection
iii. Escape user inputs for security
iv. Attempt to insert query execution
Closing a connection
The below is Html code that will determine the forms of Html.
<!DOCTYPE HTML>
<html>
<head>
<title>Contact Us</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="contact">
<h3> Add your records below so that we identify you</h3>
<form method="POST" action="connectivity.php">
First Name
<br>
<input type="text" name="name">
<br> Last Name
<input type="text" name="name">
<br>
<input type="text" name="email">
<br> Email Address
<br>
<textarea rows="10" cols="50" maxlength="100"
name="message"></textarea>
<br>
<input type="submit" value="Add Records">
</form>
</div>
</body>
CREATE DATABASE practice;
USE practice;
?>
<?php
if (isset($_POST['name'])) {
$email = $_POST['email'];
$message = $_POST['addrecords'];
$stmt->execute();