Thursday 24 February 2022

BSCCS TY VI SEM Web Programming With PHP Practical LIst

Proposed Practical List 1. Hello World program 2. Script to Capture Form Data 3. Script to Redirect form 4. Script to define and call function 5. Script to work with String function 6. Script for Index Based Array 7. Script for Associative Array 8. Script for foreach loop 9. Script to work with Query String 10. Script to work with Hidden Field 11. Script to work with Cookie 12. Script to work with Session 13. Script to demonstrate Regular Expression 14. Script to demonstrate Inheritance 15. Script to demonstrate Interface 16. Script to demonstrate Constructor and Destructor 17. Script to connect with Mysql database 18. Script to perform DML operation on database 19. Script to perform show database record on web page

========================================================================

3. Script to Redirect form

Solution:

(Membership.php)

<?php

if ( isset( $_POST["submitButton"] ) ) {

// (deal with the submitted fields here)

header( "Location: thanks.html" );

exit;

} else {

displayForm();

}

function displayForm() {

?>

<html>

<head>

<title>Membership Form</title>

</head>

<body>

<h1>Membership Form</h1>

<form action="redirect.php" method="post">

<div style="width: 30em;">

<label for="firstName">First name</label>

<input type="text" name="firstName" id="firstName" value="" /></br>

<label for="lastName">Last name</label>

<input type="text" name="lastName" id="lastName" value="" />

<div style="clear: both;">

<input type="submit" name="submitButton" id="submitButton" value=

"Send Details" />

</div>

</div>

</form>

</body>

</html>

<?php

}

?>


(Thanls.html)

<html>

<head> <title> Thank You Page </title></html>

<body>

Thank You !</br> You are redirected Here!

</body>

</html>

========================================================================

4. Script for Index Based Array

 Solution:

<html>

<head> <title> Script to define and print index based array </title></html>

<body>

<?php 

$myBook = array(“The Grapes of Wrath”, “John Steinbeck”,  1939 );

print_r($myBook); 

?>

</body>

</html>

========================================================================

7. Script for Associative Array

Solution:

<html>

<head> <title> Script to define and print Associative array </title></html>

<body>

<?php 

$myBook = array(“title” = > “The Grapes of Wrath”, “author” = > “John Steinbeck”, “pubYear” = > 1939 );

print_r($myBook); 

?>

</body>

</html>

========================================================================

8. Script for foreach loop

Solution:

<html>

<head> <title> Script to access Associative array using foreach loop</title></html>

<body>

<?php 

#Declare an associative array 

$aso_arr = array( 

"Up"=>"North", 

"Down"=>"South", 

"Left"=>"West", 

"Right"=>"East"

); 

#Use foreach loop to traverse each elements of array and display its key and value 

foreach($aso_arr as $side=>$direc) { 

echo $side . " => " . $direc . "\n"; 

?>

</body>

</html>