Thursday, July 7, 2022

Program

1.SHELL SCRIPT TO SHOW THE SYSTEM CONFIGURATIONDate

Program:

1. Currently logged user and his log name

  a. who am i

  b. who -a

2. Current shell, Home Directory, OS type, Current path setting, Current working directories

  a. Current Shell

          i. echo $SHELL

  b. Home Directory

          i. pwd

  c. CPU Information

          i. cat/proc/version

          ii. lscpu

  d. Current path setting

          i. echo $PATH

  e. Current working directories

          i. pwd -P

         f.   Show Memory Information

                     i.vmstat

EX.NO: 2 FILTER COMMANDS

Program :

The Filter Command

1.vi command:

          vi  sample.txt

2.sort command:

          sort  sample.txt

3.tail command:

          tail  sample.txt

4.head command:

          head  sample.txt

5.fmt command:

           fmt  sample.txt

EX.NO: 4 CREATE A DATABASE AND TO INSERT A  TABLE USING PHP

Program :

index.php

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01

Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-

8859-1″>

<style type=”text/css”>

<!–

body

{

 background-color: #CCCCFF;

}

–>

</style></head>

<body>

<h1 align=”center”>Creating MySql Table</h1>

<form name=”form1″ method=”post” action=”ch.php”>

<p>&nbsp;</p>

<p align=”center”>

<input name=”dbex” type=”submit” id=”dbex” value=”Database

Exists”>

<input name=”cr” type=”submit” id=”cr” value=”Create Table”>

</p>

<p>&nbsp;</p>

</form>

<p>&nbsp;</p>

</body> </html>

connection.php

<?php

$lh=”localhost”;

 $us=”root”;

 $pd=””;

 $db1=”pg4″;

 $con=mysqli_connect($lh,$us,$pd,$db1);

 ?>

Ch.php

<?php

if(isset($_POST[‘dbex’]))

{

 include “connection.php”;

 if($con)

  echo “Database connected successfully”;

 else

  echo “Database does not exist”;

}

else

{

 if(isset($_POST[‘cr’]))

 {

  include “connection.php”;

  $sql = “CREATE TABLE persons(

  id INT NOT NULL PRIMARY KEY

AUTO_INCREMENT,

  first_name VARCHAR(30) NOT NULL,

  last_name VARCHAR(30) NOT NULL,

  email VARCHAR(70) NOT NULL UNIQUE

)”;

if(mysqli_query($con, $sql))

{

echo “Table created successfully.”;

else
 

{

echo “ERROR: Could not able to execute $sql. ” . mysqli_error($con);

}

mysqli_close($con);

}}

?>

<html><style type=”text/css”>

<!–

body {

 background-color: #9999CC;

}

–>

</style>

<body>

<form name=”form1″ method=”post” action=”ch.php”>

<p>&nbsp;</p>

<p align=”center”>

<input name=”dbex” type=”submit” id=”dbex” value=”Database

Exists”>

<input name=”cr” type=”submit” id=”cr” value=”Create Table”>

</p>

<p>&nbsp;</p>

</form></body></html>

EX.NO: 5                   CREATE A TABLE USING CLASSES

Program :

 <?php  

$host = ‘localhost’;  

$user = ‘root’;  

$pass = ”;  

$dbname = ‘midhu’;  

$conn = mysqli_connect($host, $user, $pass,$dbname);  

if(!$conn){  

  die(‘Could not connect: ‘.mysqli_connect_error());  

}  

echo ‘Connected successfully<br/>’;  

$sql = “create table emp1(id INT AUTO_INCREMENT,name

VARCHAR(20) NOT NULL,  

emp_salary INT NOT NULL,primary key (id))”;  

if(mysqli_query($conn, $sql)){  

 echo “Table emp5 created successfully”;  

}else{  

echo “Could not create table: “. mysqli_error($conn);  

}  

mysqli_close($conn);  

?>

EX.NO: 6                             UPLOAD A FILE TO THE SERVER

Program :

Front.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0

Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

<title>Untitled Document</title>

<style type=”text/css”>

body {

 background-color: #C9F;

}

</style>

</head>

<body>

<form action=”uploader.php” method=”post” enctype=”multipart/form-

data”>

<p align=”center”><h1 align=”center”>File Uploading</h1></p>

<table width=”441″ border=”1″>

<tr>

<td height=”86″>Select File: </td>

<td><input type=”file” name=”fileToUpload”/></td>

</tr>

<tr>

<td height=”86″>&nbsp;</td>

<td><input type=”submit” value=”Upload” name=”submit”/></td>

</tr>

</table>

<p>&nbsp;</p>

<p><br />

</p>

</form>

</body></html>

Uploader.php

<style type=”text/css”>

body {

 background-color: #C9F;

}

</style>

<p><h1>File uploading</h1></p>

<p>&nbsp;</p>

<?php

$target_path = “e:/”;  

$target_path = $target_path.basename(

$_FILES[‘fileToUpload’][‘name’]);   

    if(move_uploaded_file($_FILES[‘fileToUpload’][‘tmp_name’],

$target_path)) {  

echo “File uploaded successfully!”;  

} else{

echo “Sorry, file not uploaded, please try again!”;  

}  

?>

EX.NO: 7                     DATA STORED IN A MYSQL TABLE USING

Program :

first.php

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01

Transitional//EN”

“http://www.w3.org/TR/html4/loose.dtd”>

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-

8859-1″>

<style type=”text/css”>

<!–

body {

 background-color: #9966FF;

}

.style1 {font-size: xx-large}

–>

</style></head>

<body>

<div align=”center” class=”style1″>

<p>Retrieve Records from a Database Table </p>

<form name=”form1″ method=”post” action=”display.php”>

<table width=”52%” height=”129″  border=”1″>

<tr>

<td width=”51%”><div align=”center”>

<input name=”cc” type=”submit” id=”cc” value=”Check Connection”>

</div></td>

<td width=”49%”><div align=”center”>

<input name=”dr” type=”submit” id=”dr” value=”Display Records”>

</div></td>

</tr>

</table>

</form>

<p>&nbsp;</p>

</div>

</body> </html
 

connection.php:

<?php

$lh=”localhost”;

$us=”root”;

$pd=””;

$db=”pg4″;

$con=mysqli_connect($lh,$us,$pd,$db);

?>

display.php

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01

Transitional//EN”

“http://www.w3.org/TR/html4/loose.dtd”>

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-

8859-1″>

<style type=”text/css”>

<!–

body,td,th {

 color: #FF0000;

}

body {

 background-color: #99FFCC;

}

.style1 {font-size: xx-large}

–>

</style></head>

<body>

<div align=”center”>

<p class=”style1″>Display Records from the Table</p>

<form name=”form1″ method=”post” action=””>

<p>&nbsp;</p>

<table width=”50%”  border=”1″>
 

<tr>

<td>ID</td>

<td>FIRST NAME </td>

<td>LAST NAME </td>

<td>EMAIL</td>

</tr>

 <?php

  include “connection.php”;

  if(isset($_POST[‘cc’]))

  {

   if($con)

    echo “Connected Successfully”;

   else

    echo “Connection Failed”;

  }

  if(isset($_POST[‘dr’]))

  {

   $q=”SELECT * FROM persons”;

   $r=mysqli_query($con,$q);

   while($row=mysqli_fetch_array($r))   

   {

    print “<tr><td>”;

    echo $row[“id”];

    print “</td><td>”;

    echo $row[‘first_name’];

    print “</td><td>”;

    echo $row[‘last_name’];

    print “</td><td>”;

    echo $row[’email’];

    print “</td></tr>”;

   }

  }

  ?>

</table>

<p>&nbsp;</p>

</form>

<p class=”style1″>&nbsp; </p> </div></body></html>

EX.NO: 8 CREATE A DIRECTORY AND TO READ  CONTENTS USING PHP

Program :

directory.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0

Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

<title>Untitled Document</title>

<style type=”text/css”>

body,td,th {

 color: #C00;

}

body {

 background-color: #9FF;

}

</style>

</head>

<body>

<div align=”center”><h1>Working with Directories</h1>

<p>&nbsp;</p>

<p>

<h2 align=”left”>Content of the current working directory: <?php

$cur_dir = getcwd();  echo $cur_dir;?></h2></p>

</div>

</body>

</html><?php

// open the current directory

$dhandle = opendir(‘.’);

$files = array();

if ($dhandle) 

{

while (false !== ($fname = readdir($dhandle)))

{
 

if (($fname != ‘.’) && ($fname != ‘..’) &&

          ($fname != basename($_SERVER[‘PHP_SELF’]))) 

{

          $files[] = (is_dir( “./$fname” )) ? “(Dir) {$fname}” : $fname;

      }

   }

closedir($dhandle);

}

echo “<select name=\”file\”>\n”;

foreach( $files as $fname )

{

echo “<option>{$fname}</option>\n”;

}

echo “</select>\n”; ?>

EX.NO: 9                               STUDENTS MARK 

Program :

Index.php

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01

Transitional//EN”

“http://www.w3.org/TR/html4/loose.dtd”>

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-

8859-1″>

<style type=”text/css”>

<!–

body {

 background-color: #FFCCFF;

}

.style1 {

 font-size: xx-large;

 font-weight: bold;

}

–>

</style></head>

<body>

<div align=”center” class=”style1″>

<p>STUDENT DETAILS </p>

<form name=”form1″ method=”post” action=”sheet.php”>
 

<table width=”55%” height=”590″  border=”1″>

<tr>

<td>Register Number </td>

<td><input name=”rg” type=”text” id=”rg”></td>

</tr>

<tr>

<td>Name of the Student </td>

<td><input name=”na” type=”text” id=”na” size=”50″></td>

</tr>

<tr>

<td>RDMS</td>

<td><input name=”rd” type=”text” id=”rd”></td>

</tr>

<tr>

<td>Visual Basic Programming </td>

<td><input name=”vb” type=”text” id=”vb”></td>

</tr>

<tr>

<td>Open Source Tools </td>

<td><input name=”os” type=”text” id=”os”></td>

</tr>

<tr>

<td>Oracle Lab </td>

<td><input name=”rdl” type=”text” id=”rdl”></td>

</tr>
 

<tr>

<td>VB Programming Lab </td>

<td><input name=”vbl” type=”text” id=”vbl”></td>

</tr>

<tr>

<td>Open Source Lab </td>

<td><input name=”osl” type=”text” id=”osl”></td>

</tr>

<tr>

<td>&nbsp;</td>

<td><input name=”mk” type=”submit” id=”mk”

value=”Markstatement”>

</td>

</tr>

</table>

</form>

<p>&nbsp;</p>

</div>

</body>

</html>

Connection.php

<?php

$lh=”localhost”;

$us=”root”;

$pd=””;

$db=”stu1″;

$cp=mysqli_connect($lh,$us,$pd,$db);

?>

Sheet.php

<html><style type=”text/css”>

<!–

body {

 background-color: #FFCCFF;

}

.style1 {font-size: xx-large}

body,td,th {

 font-size: medium;

 color: #660066;

}

–>

</style>

<body>

<div align=”center”>
 

<span class=”style4″></span>

<p><strong><span class=”style1″>Mark Statement

</span></strong></p>

<form name=”form1″ method=”post” action=””>

<?php

    include “conp.php”;

      $rg1=$_POST[‘rg’];

 $na1=$_POST[‘na’];

 $m1=$_POST[‘rd’];

 $m2=$_POST[‘vb’];

 $m3=$_POST[‘os’];

 $m4=$_POST[‘rdl’];

 $m5=$_POST[‘vbl’];

 $m6=$_POST[‘osl’];

 if(isset($_POST[‘mk’]))

  {

            $q1=”INSERT INTO

                mks(regno,name,m1,m2,m3,m4,m5,m6) 

                      VALUES(‘$rg1′,’$na1’,$m1,$m2,$m3,$m4,$m5,$m6)”;

  $res1=mysqli_query($cp,$q1);

  }

 $q2=”SELECT * FROM mks where regno=’$rg1′”;

 $res2=mysqli_query($cp,$q2);
 

 while($row=mysqli_fetch_array($res2))

 {

          echo  “<table width=’73%’  border=’1′><tr><td

            width=’28%’>Register Number </td><td

            width=’25%’>”.$rg1.”</td><td width=’10%’>Name</td><td

              width=’37%’>”.$na1.”</td></tr></table>”;

  echo “<br>”;

  echo “<br>”;

  echo “<br>”;

  echo “<br>”;

          echo “<table width=’50%’  border=’1′><tr><td><span

                  class=’style2′>Subjects</span></td><td><span

                class=’style2′>Marks</span></td></tr>”;

  $s1=$row[‘m1’];

          echo “<tr><td>Relational Database Management

            System</td><td>$s1</td></tr>”;

  $s2=$row[‘m2’];

  echo “<tr><td>Visual Basic

Programming</td><td>$s2</td></tr>”;

  $s3=$row[‘m3’];

  echo “<tr><td>Open Source Tools</td><td>$s3</td></tr>”;

  $s4=$row[‘m4’];

  echo “<tr><td>Oracle Lab</td><td>$s4]</td></tr>”;

  $s5=$row[‘m5’];

  echo “<tr><td>VB Lab</td><td>$s5</td></tr>”;
 

  $s6=$row[‘m6’];

  echo “<tr><td>VB Lab</td><td>$s6</td></tr>”;

  $tot=$s1+$s2+$s3+$s4+$s5+$s6;

  echo “<tr><td>Total</td><td>$tot</td></tr>”;

 }

 ?>

</table>

<p align=”right” class=”style3″><a href=”index.php”>BACK</a></p>

</form>

<p><strong></strong></p> </div></body></html>

EX.NO: 10                               Shopping Cart Web page 

Program :

Index.php

<?php

session_start();

$connect = mysqli_connect(“localhost”, “root”, “”, “cart”);

if(isset($_POST[“add_to_cart”]))

{

 if(isset($_SESSION[“shopping_cart”]))

 {

  $item_array_id =

  array_column($_SESSION[“shopping_cart”], “item_id”);

  if(!in_array($_GET[“id”], $item_array_id))

  {

  $count = count($_SESSION[“shopping_cart”]);

  $item_array = array(

  ‘item_id’  => $_GET[“id”],

  ‘item_name’  => $_POST[“hidden_name”],

  ‘item_price’  => $_POST[“hidden_price”],

  ‘item_quantity’  => $_POST[“quantity”]);

  $_SESSION[“shopping_cart”][$count] = $item_array;

  }

  else

  {

  echo ‘<script>alert(“Item Already Added”)</script>’;

  }
 

 }

 else

 {

  $item_array = array(

  ‘item_id’  => $_GET[“id”],

  ‘item_name’  => $_POST[“hidden_name”],

  ‘item_price’  => $_POST[“hidden_price”],

  ‘item_quantity’  => $_POST[“quantity”]);

  $_SESSION[“shopping_cart”][0] = $item_array;

 }}

if(isset($_GET[“action”]))

{

 if($_GET[“action”] == “delete”)

 {

  foreach($_SESSION[“shopping_cart”] as $keys => $values)

  {

  if($values[“item_id”] == $_GET[“id”])

  {

  unset($_SESSION[“shopping_cart”][$keys]);

  echo ‘<script>alert(“Item Removed”)</script>’;

  echo ‘<script>window.location=”index.php”</script>’;

  }

  }

 }}

 ?>
 

<!DOCTYPE html>

<html>

<head>

<title>Shopping Cart In PHP and MySql</title>

<script

      src=”https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js”><

/script>

<link rel=”stylesheet”

      href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.mi

n.css” />

<script

      src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.j

s”></script>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-

8859-1″><style type=”text/css”>

<!–

body {

 background-color: #CC99FF;

}

–>

</style></head>

<body>

 <br />

 <div class=”container”>

 <br />
 

 <br />

 <br />

 <h3 align=”center”>Shoping Cart With PHP AndMySql</h3><br

/>

 <br /><br />

<?php

 $query = “SELECT * FROM tbl_product ORDER BY id ASC”;

 $result = mysqli_query($connect, $query);

 if(mysqli_num_rows($result) > 0)

 {

  while($row = mysqli_fetch_array($result))

  {

 ?>

<div class=”col-md-4″>

<form method=”post” action=”index.php?action=add&id=<?php echo

$row[“id”]; ?>”>

<div style=”border:3px solid #5cb85c; background-color:whitesmoke;

border-radius:5px; padding:16px;” align=”center”>

<imgsrc=”<?php echo $row[“image”]; ?>” class=”img-responsive”

/><br />

<h4 class=”text-info”><?php echo $row[“name”]; ?></h4>

<h4 class=”text-danger”>$ <?php echo $row[“price”]; ?></h4>

<input type=”text” name=”quantity” value=”1″ class=”form-control” />

<input type=”hidden” name=”hidden_name” value=”<?php echo

$row[“name”]; ?>” />
 

<input type=”hidden” name=”hidden_price” value=”<?php echo

$row[“price”]; ?>” />

<input type=”submit” name=”add_to_cart” style=”margin-top:5px;”

class=”btnbtn-success” value=”Add to Cart” />

</div>

</form>

</div>

<?php

 }

 }

?>

<div style=”clear:both”></div>

<br />

<h3>Order Details</h3>

<div class=”table-responsive”>

<table class=”table table-bordered”>

<tr>

<th width=”40%”>Item Name</th>

<th width=”10%”>Quantity</th>

<th width=”20%”>Price</th>

<th width=”15%”>Total</th>

<th width=”5%”>Action</th>

</tr>

<?php

 if(!empty($_SESSION[“shopping_cart”]))
 

 {

  $total = 0;

  foreach($_SESSION[“shopping_cart”] as $keys => $values)

  {

?>

<td><?php echo $values[“item_name”]; ?></td><a

href=”../Prog1″>Prog1</a>

<tr>

<td><?php echo $values[“item_quantity”]; ?></td>

<td>$ <?php echo $values[“item_price”]; ?></td>

<td>$ <?php echo number_format($values[“item_quantity”] *

$values[“item_price”], 2);?></td>

<td><a href=”index.php?action=delete&id=<?php echo

$values[“item_id”]; ?>”><span class=”text-

danger”>Remove</span></a></td>

</tr>

<?php

 $total = $total + ($values[“item_quantity”] *

$values[“item_price”]);

  }

?>

<tr>

<td colspan=”3″ align=”right”>Total</td>

<td align=”right”>$ <?php echo number_format($total, 2); ?></td>

<td></td>
 

</tr>

<?php

 }

?>

</table>

</div>

</div>

</div>

<br /> </body></html>

Previous articleOPEN SOURCE TOOLS
adminhttps://www.dreamtobig.com
CEO of Dremtobig.com Web Designer and content writer.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular