Professional Documents
Culture Documents
Practical file
of
wbp lab
(BCA 172)
SUBMITTED BY submitted to
LAgneshwar.s mr.lekhraj prajapati
(PROFESSOR)
if ($current_day == "Mon") {
echo "The day is Monday";
$current_hour = date('H');
<?php
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
?>
</body>
</html>
Q7. Write a program to implement oops concepts?
<?php
class demo
{
private $a= "hello javatpoint";
public function display()
{
echo $this->a;
}
}
$obj = new demo();
$obj->display();
?>
Q8. Write a program to create file?
<?php
$f = fopen($filename, 'wb');
if (!$f) {
die('Error creating the file ' . $filename);
}
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
$CarID = $_POST['CarID'];
$BrandName = $_POST['BrandName'];
$OwnersName = $_POST['OwnersName'];
$RegistrationNumber = $_POST['RegistrationNumber'];
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>
Q12. Design a form which upload and display image in
php?
<!DOCTYPE html>
<html>
<head>
<title>Image Upload And Display</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<label>Title</label>
<input type="text" name="title">
<label>File Upload</label>
<input type="File" name="file">
<input type="submit" name="submit">
<input type="submit" name="display" value="Display">
</form>
<table>
<tr>
<th>name</th>
<th>image</th>
</tr>
<?php
$localhost = "localhost"; #localhost
$dbusername = "root"; #username of phpmyadmin
$dbpassword = ""; #password of phpmyadmin
$dbname = "dbase"; #database name
#connection string
$conn = mysqli_connect($localhost,$dbusername,$dbpassword,
$dbname);
if (isset($_POST["submit"]))
{
#retrieve file title
$title = $_POST["title"];
#file name with a random number so that similar dont get replaced
$pname = rand(1000,10000)."-".$_FILES["file"]["name"];
#temporary file name to store file
$tname = $_FILES["file"]["tmp_name"];
#upload directory path
$uploads_dir = 'img';
#TO move the uploaded file to specific location
move_uploaded_file($tname, $uploads_dir.'/'.$pname);
#sql query to insert into database
$sql = "INSERT into fileup(title,image)
VALUES('$title','$pname')";
if(mysqli_query($conn,$sql)){
echo "File Sucessfully uploaded";
}
else{
echo "Error";
}
}if( (isset($_POST["display"]))){
$sql = "SELECT * FROM fileup";
$q=mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($q)){
?>
<tr>
<td><?php echo $row['title'];?></td>
<td><img src="img/<?php echo $row["image"];?>"
height="100" width="100"></td>
</tr>
<?php }}
?>
</table>
</body>
</html>
Q13. Create admin login, logout form using session
variables?
Form.php
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Login.PHP
<!DOCTYPE html>
<html>
<body>
<?php
$uid = $_POST['userid'];
$pw = $_POST['password'];
</body>
</html>
Logout.PHP
<!DOCTYPE html>
<html>
<body>
<?php
session_start();
session_destroy();
?>
</body>
</html>
<?php
if( $_GET["name"] || $_GET["age"] ) {
echo "Welcome ". $_GET['name']. "<br />";
echo "You are ". $_GET['age']. " years old.";
exit();
}
?>
<html>
<body>
</body>
</html>