Web lab N-SCHEME(11-15)pgm and op

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

EX.

NO : 11

PROGRAM :

<?php

// Using strlen()

$r='God Loves You';

echo "The Length of the String is ".strlen($r);

echo "<br>";

// Using strrev()

$s="God is Great";

echo "The Reversed String is ".strrev($s);

echo "<br>";

// Using strtolower()

$t='God Loves All';

echo "The Lowercase String is ".strtolower($t);

echo "<br>";

// Using strtoupper()

$u='All Students are Good';

echo "The Uppercase String is ".strtoupper($u);

echo "<br>";

// Using str_word_count()

$v="Today Climate is Good";

echo "The Number of words in the String is ".str_word_count($v);

echo "<br>";

?>
OUTPUT :
EX.NO : 12

PROGRAM :

<?php

$ceu=array("India"=>"Delhi",

"United States"=>"Wasington",

"France"=>"Paris",

"Germany"=>"Berlin",

"Greace"=>"Athens",

"United Kingdom"=>"London",

"cyprus"=>"Nicosia",

"Lithunania"=>"Vilnius",

"Hungary"=>"Budapest",

"Austria"=>"Vienna",

"Poland"=>"warsaw");

asort($ceu);

foreach($ceu as $country => $capital)

echo "The capital of $country is $capital"."<br>";

?>
OUTPUT :
EX.NO : 13

PROGRAM :

<?php

echo 'Current data in different format'.'<br>';

echo date("Y/m/d")."<br>";

echo date ("y.m.d")."<br>";

echo date("d-m-y")."<br>";

echo 'Current time in seconds since the beginning of unix';

echo '<br>';

echo time().'<br>';

echo 'date/time information'.'<br>';

print_r(getdate());

?>
OUTPUT :
EX.NO : 14

PROGRAM :

<?php

$connect=mysqli_connect("localhost:3307","root","");

$sql="create database if not exists simpleitems";

if($connect->query($sql)===true)

echo "Database items created successfully <br><br>";

else

echo "error creating database:".$conn->error;

$connect=mysqli_connect("localhost:3307","root","","items");

$sql = "CREATE TABLE if not exists tbl_productitem(name varchar(255) UNIQUE


NOT NULL, quantity int(6) NOT NULL,

price double(10,2) NOT NULL)";

if($connect->query($sql)=== TRUE)

echo "Table tbl_product created successfully <br><br>";

else{

echo "Error creating table:".$connect->error;

}
if(isset($_POST["add_to_table"]))

$name=$_POST["name"];

$quantity=intval($_POST["quantity"]);

$rate=intval($_POST["rate"]);

$sql= "INSERT INTO tbl_productitem(name, quantity, price) VALUES ('".$name."',".


$quantity.",".$rate.")";

// echo $sql;

if($connect->query($sql)===TRUE){

echo "<br> New record created successfully";

else

echo "Error:".$sql."<br>".$connect->error;

if(isset($_GET["delete"]))

$item_name=$_GET["item_name"];

$delete=$_GET["delete"];

if($_GET["delete"]==1)

$sql="DELETE FROM tbl_productitem WHERE name='".$item_name."'";

if($connect->query($sql)==TRUE)
{

echo "Record deleted successfully";

else

echo "Error deleting record:".$connect->error;

?>

<!DOCTYPE html>

<html>

<head><title>Edwin Daya</title></head>

<body>

<br/>

<div class="container"style="width:700px;">

<h3 align="center">Simple Item Table</h3><br/>

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

<?php

$sql="SELECT * FROM tbl_productitem";

$result=$connect->query($sql);

?>

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

<br/>
<h3>Items</h3>

<div class="table-responsive">

<table class="table table-bordered">

<tr>

<th width="10%" style="text-align:center">S NO</th>

<th width="30%" style="text=align:center">Item Name</th>

<th width="20%" style="text=align:center">Quantity<th>

<th width="20%" style="text-align:center">Price-RS</th>

<th width="20%"></th>

</tr>

<?php if($result->num_rows> 0) {

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

$ii=1;

while($row=$result->fetch_assoc()){ ?>

<tr>

<td><?php echo $ii++;?></td>

<td><?php echo $row["name"];?></td>

<td style="text-align:center"><?php echo $row["quantity"];?></td>

<td style="text-align:right"><?php echo $row["price"];?></td>

<td style="text="text-align:center">

<a href="<?php echo $actual_link;?>?delete=1&item_name=<?php echo $row['name'];?


>">Delete</a></td>

</tr>

<?php
}

?>

<tr><td>&nbsp;</td>

<td>

<input type="text" name="name" </td>

<td><input type="text" name="quantity" style="width:100px"/></td>

<td><input type="text" name="rate" value="0"


style="width:150px;text-align:right"/></td>

<td><input type="submit" name="add_to_table" value="Add to Table"/></td>

</tr>

</table>

</div>

</form>

</div>

</body>

</html>
OUTPUT :
EX.NO : 15

PROGRAM :

<?php

$connect=new mysqli("localhost","root","");

$sql="Create database if not exists scart";

if($connect->query($sql)===True){

echo "Database created successfully";

} else {

echo "Error creating database: ".$connect->connect_error;

$connect=new mysqli("localhost","root","","scart");

if ($connect->connect_error){

die("Connection failed: ".$connect->connect_error);

$sql="CREATE TABLE IF NOT EXISTS 'tbl_product'('id' int(11) not null


auto_increment,'name' varchar(255) not null,'image' varchar(255) not null,'price'
double(10,2)not null, primary key('id'))";

if($connect->query($sql)===TRUE){

echo "Table tbl_product created successfull";

} else {

echo "Error creating table: ".$connect->error;

$sql="insert into 'tbl_product' ('id','name',image','price')values(1,'samsung j2


pro','1.jpg',100.00),(2,'HP Notebook',2.jpg',299.00),(3,'Panasonic t44
Lite',3.jpg',125.00)";
if($connect->query($sql)===true){

echo "New record created successfully";

} else {

echo "Error: ".$sql . "<br>" .$connect->error;

if(isset($_post["add_to_cart"])){

if(isset($_session["shopping_cart"])){

$item_array_id=array_column($_session["shopping_cart"],"item_id");

if(!in_array($_FET["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_quanity' => $_post["quantity"]

);

$_session["shopping_cart"][$count]=$item_array;

else {

echo "<script>alert('Item Already Added')</script>";

echo "<script>window.location='index.php'</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> Edwin Daya | Shopping cart</title>

</head>

<body align="centre">

<br>

<div class="container"style="width:7--px;margin-left:200px">

<h3 align="centre">Simple PHP Mysql Shopping Cart</h3><br>

<?php

$query="Select * from tbl_product order by id ASC";

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

if(mysqli_num_row($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:1px solid #333; background-color:#f1f1f1;

border-radius:5px; padding:10px"align="centre">

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

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

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

<input type="hidden" name="hiddent_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["shooping_cart"]as $keys => $values) {

?>
<tr>

<td><?php echo $values["item_name"];?> </td>

<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="roght">Total</td>

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

<td></td>

</tr>

<?php } ?>

</table>

</div>

</div>

<br/>
</body>

</html>

OUTPUT :

You might also like