TASK – PHP
Solution :
ADD PHP:
<style>
html { height: 100% }
::-moz-selection { background: #fe57a1; color: #fff; text-shadow: none; }
::selection { background: #fe57a1; color: #fff; text-shadow: none; }
body { background-image: radial-gradient( cover, rgba(92,100,111,1) 0%,rgba(31,35,40,1) 100%), url(‘http://i.minus.com/io97fW9I0NqJq.png’) }
.login {
background: #eceeee;
border: 1px solid #42464b;
border-radius: 6px;
height: 257px;
margin: 20px auto 0;
width: 298px;
}
.submit h1 {
background-image: linear-gradient(top, #f1f3f3, #d4dae0);
border-bottom: 1px solid #a6abaf;
border-radius: 6px 6px 0 0;
box-sizing: border-box;
color: #727678;
display: block;
height: 43px;
font: 600 14px/1 ‘Open Sans’, sans-serif;
padding-top: 14px;
margin: 0;
text-align: center;
text-shadow: 0 -1px 0 rgba(0,0,0,0.2), 0 1px 0 #fff;
}
input[type=”date”], input[type=”text”] {
background: url(‘http://i.minus.com/ibhqW9Buanohx2.png’) center left no-repeat, linear-gradient(top, #d6d7d7, #dee0e0);
border: 1px solid #a1a3a3;
border-radius: 4px;
box-shadow: 0 1px #fff;
box-sizing: border-box;
color: #696969;
height: 39px;
margin: 31px 0 0 29px;
padding-left: 37px;
transition: box-shadow 0.3s;
width: 240px;
}
input[type=”date”]:focus, input[type=”text”]:focus {
box-shadow: 0 0 4px 1px rgba(55, 166, 155, 0.3);
outline: 0;
}
.show-password {
display: block;
height: 16px;
margin: 26px 0 0 28px;
width: 87px;
}
.toggle {
background: url(http://i.minus.com/ibitS19pe8PVX6.png) no-repeat;
display: block;
height: 16px;
margin-top: -20px;
width: 87px;
z-index: -1;
}
.forgot:hover { color: #3b3b3b }
input[type=”submit”] {
width:240px;
height:35px;
display:block;
font-family:Arial, “Helvetica”, sans-serif;
font-size:16px;
font-weight:bold;
color:#fff;
text-decoration:none;
text-transform:uppercase;
text-align:center;
text-shadow:1px 1px 0px #37a69b;
padding-top:6px;
margin: 29px 0 0 29px;
position:relative;
cursor:pointer;
border: none;
background-color: #37a69b;
background-image: linear-gradient(top,#3db0a6,#3111);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius:5px;
box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #497a78, 0px 10px 5px #999;
}
.shadow {
background: #000;
border-radius: 12px 12px 4px 4px;
box-shadow: 0 0 20px 10px #000;
height: 12px;
margin: 30px auto;
opacity: 0.2;
width: 270px;
}
input[type=”submit”]:active {
top:3px;
box-shadow: inset 0px 1px 0px #2ab7ec, 0px 2px 0px 0px #31524d, 0px 5px 3px #999;
}
</style>
<html>
<body>
<form action=”add2.php” method=”post”>
<div>
Name :<input type=”text” name=”name” placeholder = “Name” required><br>
Date of Birth :<input type=”date” name=”date” required><br>
<input type=”submit” value=”submit”>
</div>
<div></div>
</form>
</body>
</html>
<?php
if (isset($_GET[‘mess’]))
{
$m = $_GET[‘mess’];
echo ‘<script language=”javascript”>alert(“‘.$m.'”);</script>’;
}
ADD1 PHP
<?php
include (“dbcon.php”);
$name=$_POST[‘name’];
$date=$_POST[‘date’];
if (strlen($name)<100)
{
$insert=”INSERT INTO person(id,name,birth_date) VALUES (”, ‘$name’, ‘$date’)”;
$a=mysqli_query($cn,$insert);
/*if($a)
{
echo “<script type=\”text/javascript\”>.”alert(‘Succes’);”.”</script>”;
}*/
if($a)
{
$redirectUrl = ‘add.php’;
echo ‘<script type=”application/javascript”> alert(“Succesfully Added”); window.location.href = “‘. $redirectUrl.'”;</script>’;
}
else
{
echo “Error!”. mysql_error();
}
}
else
{
echo “input is very high please select less then 100 words”;
echo “<html></br><a href=\”add.php\”>back</a></html>”;
}
?>
ADD2 PHP
<?php
include (“dbcon.php”);
$name=$_POST[‘name’];
$date=$_POST[‘date’];
if (strlen($name)<100)
{
$insert=”INSERT INTO person(id,name,birth_date) VALUES (”, ‘$name’, ‘$date’)”;
$a=mysqli_query($cn,$insert);
/*if($a)
{
echo “<script type=\”text/javascript\”>.”alert(‘Succes’);”.”</script>”;
}*/
if($a)
{
header(‘location:add.php?mess=success’);
}
else
{
echo “Error!”. mysql_error();
}
}
else
{
echo “input is very high please select less then 100 words”;
echo “<html></br><a href=\”add.php\”>back</a></html>”;
}
?>
ADDp PHP
<html>
<body>
<form action=”log.php” method=”post”>
UserName: <input type=”text” name=”username” required><br>
Password: <input type=”password” name=”password” required><br>
<input type=”submit” value=”Login”>
</form>
</body>
</html>
ADDR PHP
<?php
include(“dbcon.php”);
$sql=”select *from person”;
$rs=mysql_query($sql);?>
<form action=”instrel.php” method=”post” >
<select name=”s1″ required >
<option value=””>Select Parent</option>
<?php while($rw=mysql_fetch_array($rs)){ ?>
<option value=”<?php echo $rw[‘id’]?>”><?php echo $rw[‘name’]?></option>
<?php }
?></select> <?php
$sql2=”select *from person”;
$rs2=mysql_query($sql2);?>
<select name=”s2″ required >
<option value=””>Select Child</option>
<?php while($rw2=mysql_fetch_array($rs2)){ ?>
<option value=”<?php echo $rw2[‘id’]?>”><?php echo $rw2[‘name’]?></option>
<?php }
?></select>
<input type=”submit” name=”ADD” value=”ADD RELATION” />
</form>
CONNECTION PHP
<?php
$servername = “localhost”;
$username = “root”;
$password = “”;
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
echo “Connected successfully”;
?>
DBCON PHP
<?php
$cn=@mysqli_connect(‘127.0.0.1′,’root’,”) or die(“cannot connect to the host”);
mysqli_select_db($cn,’family’) or die(“cannot select database”);
?>
FAMILY SQL
— phpMyAdmin SQL Dump
— version 4.5.1
— http://www.phpmyadmin.net
—
— Host: 127.0.0.1
— Generation Time: May 08, 2016 at 06:46 PM
— Server version: 10.1.9-MariaDB
— PHP Version: 7.0.0
SET SQL_MODE = “NO_AUTO_VALUE_ON_ZERO”;
SET time_zone = “+00:00”;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
—
— Database: `family`
—
— ——————————————————–
—
— Table structure for table `parent`
—
CREATE TABLE `parent` (
`parent_id` int(5) NOT NULL,
`child_id` int(5) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
—
— Dumping data for table `parent`
—
INSERT INTO `parent` (`parent_id`, `child_id`) VALUES
(1, 3),
(8, 3),
(5, 1),
(9, 1);
— ——————————————————–
—
— Table structure for table `person`
—
CREATE TABLE `person` (
`id` int(5) NOT NULL,
`name` char(100) NOT NULL,
`birth_date` varchar(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
—
— Dumping data for table `person`
—
INSERT INTO `person` (`id`, `name`, `birth_date`) VALUES
(1, ‘Andrea Pirlo’, ‘1975-06-15’),
(2, ‘David Silva’, ‘1976-05-03’),
(3, ‘Mario Götze’, ‘1995-02-12’),
(4, ‘Joao Moutinho’, ‘1960-12-09’),
(5, ‘Diego Forlan’, ‘1950-11-24’),
(6, ‘Marek Hamsik’, ‘1999-06-20’),
(7, ‘Jonelle Filigno’, ‘1975-04-08’),
(8, ‘ANOUK HOOGENDIJK’, ‘1976-02-15’),
(9, ‘Julia Simic’, ‘1950-12-12’);
—
— Indexes for dumped tables
—
—
— Indexes for table `person`
—
ALTER TABLE `person`
ADD PRIMARY KEY (`id`);
—
— AUTO_INCREMENT for dumped tables
—
—
— AUTO_INCREMENT for table `person`
—
ALTER TABLE `person`
MODIFY `id` int(5) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
INDEX PHP
<html>
<head>
<style>
html { height: 100% }
::-moz-selection { background: #fe57a1; color: #fff; text-shadow: none; }
::selection { background: #fe57a1; color: #fff; text-shadow: none; }
body { background-image: radial-gradient( cover, rgba(92,100,111,1) 0%,rgba(31,35,40,1) 100%), url(‘http://i.minus.com/io97fW9I0NqJq.png’) }
.login {
background: #eceeee;
border: 1px solid #42464b;
border-radius: 6px;
height: 257px;
margin: 20px auto 0;
width: 298px;
}
.login h1 {
background-image: linear-gradient(top, #f1f3f3, #d4dae0);
border-bottom: 1px solid #a6abaf;
border-radius: 6px 6px 0 0;
box-sizing: border-box;
color: #727678;
display: block;
height: 43px;
font: 600 14px/1 ‘Open Sans’, sans-serif;
padding-top: 14px;
margin: 0;
text-align: center;
text-shadow: 0 -1px 0 rgba(0,0,0,0.2), 0 1px 0 #fff;
}
input[type=”password”], input[type=”text”] {
background: url(‘http://i.minus.com/ibhqW9Buanohx2.png’) center left no-repeat, linear-gradient(top, #d6d7d7, #dee0e0);
border: 1px solid #a1a3a3;
border-radius: 4px;
box-shadow: 0 1px #fff;
box-sizing: border-box;
color: #696969;
height: 39px;
margin: 31px 0 0 29px;
padding-left: 37px;
transition: box-shadow 0.3s;
width: 240px;
}
input[type=”password”]:focus, input[type=”text”]:focus {
box-shadow: 0 0 4px 1px rgba(55, 166, 155, 0.3);
outline: 0;
}
.show-password {
display: block;
height: 16px;
margin: 26px 0 0 28px;
width: 87px;
}
input[type=”checkbox”] {
cursor: pointer;
height: 16px;
opacity: 0;
position: relative;
width: 64px;
}
input[type=”checkbox”]:checked {
left: 29px;
width: 58px;
}
.toggle {
background: url(http://i.minus.com/ibitS19pe8PVX6.png) no-repeat;
display: block;
height: 16px;
margin-top: -20px;
width: 87px;
z-index: -1;
}
input[type=”checkbox”]:checked + .toggle { background-position: 0 -16px }
.forgot {
color: #7f7f7f;
display: inline-block;
float: right;
font: 12px/1 sans-serif;
left: -19px;
position: relative;
text-decoration: none;
top: 5px;
transition: color .4s;
}
.forgot:hover { color: #3b3b3b }
input[type=”submit”] {
width:240px;
height:35px;
display:block;
font-family:Arial, “Helvetica”, sans-serif;
font-size:16px;
font-weight:bold;
color:#fff;
text-decoration:none;
text-transform:uppercase;
text-align:center;
text-shadow:1px 1px 0px #37a69b;
padding-top:6px;
margin: 29px 0 0 29px;
position:relative;
cursor:pointer;
border: none;
background-color: #37a69b;
background-image: linear-gradient(top,#3db0a6,#3111);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius:5px;
box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #497a78, 0px 10px 5px #999;
}
.shadow {
background: #000;
border-radius: 12px 12px 4px 4px;
box-shadow: 0 0 20px 10px #000;
height: 12px;
margin: 30px auto;
opacity: 0.2;
width: 270px;
}
input[type=”submit”]:active {
top:3px;
box-shadow: inset 0px 1px 0px #2ab7ec, 0px 2px 0px 0px #31524d, 0px 5px 3px #999;
}
</style>
<body>
<form action=”log.php” method=”post”>
<div class=”login”>
UserName: <input type=”text” name=”username” placeholder=”Username” required><br>
Password: <input type=”password” name=”password” placeholder=”password” required><br>
<input type=”submit” value=”Login”>
</div>
<div class=”shadow”></div>
</form>
</body>
</html>
INSTREL PHP
<?php
include (“dbcon.php”);
$parent_id=$_POST[‘s1’];
$child_id=$_POST[‘s2’];
$insert=”INSERT INTO parent(parent_id,child_id) VALUES (‘$parent_id’, ‘$child_id’)”;
if(mysql_query($insert));
//$query =new mysqli($insert)or die (mysql_error());
?>
LOG PHP
<?php
//session_start();
$username=$_POST[‘username’];
$password=$_POST[‘password’];
$hashed_password = crypt(‘password123’);
$admin=”admin”;
$password1= hash_equals($hashed_password, crypt($password, $hashed_password));
if ($username==$admin && $password==$password1)
{
//$_SESSION[‘user’]=$username;
//echo “$username”;
header (“location:add.php”);
}
else
{
header (“location:index.php”);
//echo “please enter correct username and password”;
}
?>
LOGIN PHP
<?php
session_start();
$username=$_POST[‘username’];
$password=$_POST[‘password’];
if ($username==’admin’ && $password=’pasword123′)
{
header (“location:add.php”);
}
else
{
header (“location:index.php”);
}
?>
PERSON PHP
<?php
include(“dbcon.php”);
$sql=”select *from person”;
$rs=mysql_query($sql);?>
<table border=”1″>
<tr>
<th>ID</th>
<th>Name</th>
<th>Date Of birth</th></tr>
<?php while($rw=mysql_fetch_array($rs)){ ?>
<tr>
<tr>
<td><?php echo $rw[‘id’]?> </td>
<td><?php echo $rw[‘name’]?> </td>
<td><?php echo $rw[‘birth_date’]?> </td>
</tr>
<?php }
?></table>