1) Create student registration form and display details in the
next page. (Use sticky form
concept).
reg.php
<html>
<body>
<form method ="post" action="next.php">
<!--<form method ="post" action="reg.php">-->
<b>Student No:- </b><input type="text"
name="sno" value="<?php if(isset($_POST['sno']))echo
$_POST['sno'];?>"<br>
<b>StudentName:- </b><input type="text"
name="sname" value="<?php if(isset($_POST['sname']))echo
$_POST['sname'];?>"<br>
<b>Student city:- </b><input type="text"
name="city" value="<?php if(isset($_POST['city']))echo
$_POST['city'];?>"<br>
<input type="submit" name="submit"
value="save">
<input type="hidden" name="submit"
value="true">
</form>
</body>
</html>
next.php
<?php
if(isset($_POST['submit']))
{
$sno=$_POST['sno'];
$sname=$_POST['sname'];
$city=$_POST['city'];
if((!empty($sno))&&(!empty($sname))&&(!empty($city)))
echo"<b>$sno</b><br>";
echo"<b>$sname</b><br>";
echo"<b>$city</b><br>";
}
?>
2)Write Ajax program to print Movie details by selecting an
Actor’s name.
Create table MOVIE and ACTOR as follows with 1 : M cardinality
MOVIE(mno, mname, release_yr) and ACTOR(ano, aname)
actor.html
<html>
<head>
<script>
function showHint(str)
{
if (str=="")
{
document.getElementById("mydiv").innerHTML =
"";
return;
}
if(window.XMLHttpRequest)
{
XHRobj=new XMLHttpRequest();
}
else
{
XHRobj=new ActiveXObject("Microsoft.XMLHTTP");
}
XHRobj.onreadystatechange = function()
{
if (XHRobj.readyState == 4 && XHRobj.status == 200)
{
document.getElementById("mydiv").innerHTML =
XHRobj.responseText;
}
}
XHRobj.open("GET", "mactor.php?q=" + str,
true);
XHRobj.send();
}
</script>
</head>
<body>
<p><b>Actor Details:</b></p>
<form>
<SELECT name="aname"
onchange="showHint(this.value)">
<option value="">Select Actor Name</option>
<option value="Amir">Amir</option>
<option value="Salman">Salman</option>
</select>
</form>
<div id="mydiv"><b> Actor
info......</b></div>
</body>
</html>
mactor.php
<?php
$database="archana"; //database name
$q=$_GET["q"];
$con = mysql_connect("localhost","root"
,"");//for wamp 3rd feild is balnk
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$database", $con);
//SELECT m.mno,m.mname,m.year FROM `movie` AS m, `actor` AS a
WHERE m.mno=a.mno AND a.aname= '$q';
//$result=mysql_query("select * from movie,actor where
actor.aname='".$q"'" and movie.mno=actor.mno ;
$result=mysql_query("SELECT m.mno,m.mname,m.year FROM `movie`
AS m, `actor` AS a WHERE m.mno=a.mno AND a.aname= '$q'");
echo"<table border='1'>";
echo"<tr><th>mno</th><th>mname</th><th>year</th></tr>";
while($row=mysql_fetch_array($result))
{
echo"<tr><td>";
echo $row['mno'];
echo"</td><td>";
echo $row['mname'];
echo"</td><td>";
echo $row['year'];
echo"</td></tr>";
}
echo"</table>";
mysql_close($con);
?>
Another way
<html>
<head>
<script>
function showHint(str)
{
if (str=="")
{
document.getElementById("mydiv").innerHTML =
"";
return;
}
if(window.XMLHttpRequest)
{
XHRobj=new XMLHttpRequest();
}
else
{
XHRobj=new ActiveXObject("Microsoft.XMLHTTP");
}
XHRobj.onreadystatechange = function()
{
if (XHRobj.readyState == 4 && XHRobj.status == 200)
{
document.getElementById("mydiv").innerHTML =
XHRobj.responseText;
}
}
XHRobj.open("GET", "mactor.php?q=" + str,
true);
XHRobj.send();
}
</script>
</head>
<body>
<p><b>Actor Details:</b></p>
<form>
<?php
$database="archana"; //database name
$con = mysql_connect("localhost","root"
,"");//for wamp 3rd feild is balnk
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$database", $con);
$result=mysql_query("SELECT * from `actor` ");
?>
<SELECT name="aname"
onchange="showHint(this.value)">
<option value="">Select Actor Name</option>
<?php while($row=mysql_fetch_array($result))
{
?>
<option value="<?php echo
$row['aname']?>"><?php echo $row['aname']?></option>
<?php }?>
</select>
</form>
<div id="mydiv"><b> Book
info......</b></div>
</body>
</html>