Wednesday, 27 December 2017

AWT-Slip10

1) Write a PHP script to accept username and password. If in the first three chances, username and password entered is correct, then display second form, otherwise display error message.

(Use Session)              

<?php
//$_SESSION['chance']='';
session_start();
//session_register("chance");
//session_register("chance");
//echo $_SESSION['chance'];
if($_SERVER['REQUEST_METHOD']=='GET')
{
 ?>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
 <B>Name</b><input type="text" name="fname" value="<?php if(isset($_POST['fname']))echo  $_POST['fname'];?>"/>
 <B>password</b><input type="pwd" name="pwd" value="<?php if(isset($_POST['pwd']))echo  $_POST['pwd'];?>"/>
  <input type="submit" name="submited" value="submit">
  </form>
<?php
}
elseif($_SERVER['REQUEST_METHOD']=='POST')
{
 $name=$_POST['fname'];
 $pwd=$_POST['pwd'];
  if(($name=="n")&&($pwd=="e"))echo "hi<a href='next.php'>next form</a></br>";
  else {
  $_SESSION['chance']++;
  echo "wrong username & password, Chance ".$_SESSION['chance']." gone!!!";
  //$_SESSION['chance'] = $chance;
 }
 if($_SESSION['chance']==3) echo"<br/>sorry....ur chances are finished";
}
else{
 die("not able");
}
?>                                                                                                                 

 

2)Create a form to accept student information (name,class, address). Once the student information is accepted, accept marks in nextform (Java, PHP, ST, IT, pract1, and project). Display the mark sheet for thestudent in the next form containing name, class, marks of the subject, totaland percentage(Use $_COOKIE).  

first.php

<html>
<body>
<form method ="post" action="second.php">
<b>Student No:- </b><input type="text" name="sno"></br>
<b>Student Name:- </b><input type="text" name="sname"></br>
<b>Student class:- </b><input type="text" name="class"></br>
<b>Student address:- </b><input type="text" name="address"></br>
<input type="submit" value="save">
</form>
</body>
</html>

second.php
<html>
<body>

<?php
/*session_start();
$_SESSION["sno"]=$_POST["sno"];
$_SESSION["sname"]=$_POST["sname"];
$_SESSION["sclass"]=$_POST["class"];
$_SESSION["address"]=$_POST["address"];*/
setCookie('sno',$_POST["sno"]);
setCookie('sname',$_POST["sname"]);
setCookie('class',$_POST["class"]);
setCookie('address',$_POST["address"]);
echo"Hello".$_POST["sname"]."!Enter Marks....<br>";
?>
<form method ="post" action="third.php">
<b>JAVA</B><input type="text" name="JAVA"></br>
<b>PHP</B><input type="text" name="PHP"></br>
<b>ST</B><input type="text" name="ST"></br>
<b>IT</B><input type="text" name="IT"></br>
<b>Practical</B><input type="text" name="Practical"></br>
<input type="submit" name="submit" value="DISPLAY">
</form>
</body>
</html>
third.php
<html>
<body>
<?php
//session_start();
echo "<b> Student Details</b><br>";
echo" Student No:".$_COOKIE["sno"]."<br>";
echo"Student Name:".$_COOKIE["sname"]."<br>";
echo"Student class:-".$_COOKIE["class"]."<br>";
 echo"Student address:-".$_COOKIE["address"]."<br>";
 echo "<b> Student Marks</b><br>";
echo"Java:".$_REQUEST["JAVA"]."<BR>";
echo"PHP:".$_REQUEST["PHP"]."<BR>";
echo"ST:".$_REQUEST["ST"]."<BR>";
echo"IT:".$_REQUEST["IT"]."<BR>";
echo"Practical:".$_REQUEST["Practical"]."<BR>";
//echo"TOTAL:".$_REQUEST["total"]."<BR>";
//echo"Total=".$total;
if(isset($_POST['submit']))
{
$JAVA=(int)$_POST['JAVA'];
$PHP=(int)$_POST['PHP'];
$ST=(int)$_POST['ST'];
$IT=(int)$_POST['IT'];
$Practical=(int)$_POST['Practical'];
//$total=trim($_POST['cal'])
//$total=$JAVA+$PHP+$ST+$IT+$Practical;
 $total = $JAVA+$PHP+$ST+$IT+$Practical;
 echo"Total=".$total;
}
?>
</body>
</html>