Wednesday, 27 December 2017

AWT-Slip6

1)Write a PHP Script create login form and validate it (Use database and Sticky form concept)                                                                                                                                                   

<html>
<head>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method=post>
<input type=text name=txtuname value="<?php if(isset($_POST['txtuname']))echo $_POST['txtuname'];?>" ></br>
<input type=password name=txtupass value="<?php if(isset($_POST['txtupass']))echo $_POST['txtupass'];?>" ></br>
<input type=submit value="Login" name=submit>
<?php
if(isset($_POST['submit']))
$nm=$_POST['txtuname'];
$ps=$_POST['txtupass'];
$con=@mysql_connect("localhost","root","");
mysql_elect_db("archana",$con);
$result=mysql_query("select * from login where uname='$nm' and upass='$ps'");
$flag=0;
while($row=mysql_fetch_array($result))
{
  $flag++;
}
if($flag==1)
  echo "Login validated";
else
  echo "username or password invalid";
?>
</body>
</html>

2) Write a PHP Script to create a super class Vehicle having members Company and price. Derive 2 different classes LightMotorVehicle (members – mileage) and HeavyMotorVehicle (members – capacity-in-tons). Define 5 Object of each subclass and display details in table format    

 

 <?php

class vehicle

{

public $company,$price;

public function __construct($a,$b)

{

$this->company=$a;

$this->price=$b;

}

}

class Lightmotorvehicle extends vehicle

{

public $milege;

public function __construct($a,$b,$c)

{

$this->company=$a;

$this->price=$b;

$this->milege=$c;

}

public function display()

{

echo "<table border=1 width=300><tr><td>".$this->company."</td><td>".$this->price."</td><td>".$this->milege."</td></tr>";

}

}

class Heavymotorvehicle extends vehicle

{

public $capacity;

public function __construct($a,$b,$c)

{

$this->company=$a;

$this->price=$b;

$this->capacity=$c;

}

public function display()

{

echo "<table border=1 width=300>";

echo "<tr><td>".$this->company."</td><td>".$this->price."</td><td>".$this->capacity;

echo "</td></tr></table>";

}

}

$ob1=new Lightmotorvehicle("Maruti",200000,25);

$ob1->display();

$ob2=new Lightmotorvehicle("Toyota",500000,20);

$ob2->display();

$ob3=new Lightmotorvehicle("skoda",400000,15);

$ob3->display();

 

$ob4=new Heavymotorvehicle("Tata Truck",1220000,25);

$ob4->display();

$ob5=new Heavymotorvehicle("Bajaj",200000,25);

$ob5->display();

 

$ob6=new Heavymotorvehicle("mahindra",900000,25);

$ob6->display();

?>