php project learning
Thursday, 26 December 2019
Tuesday, 24 December 2019
ch-15 Using for loop in array(Indexed Array)
<html>
<head>
<title>Book Store</title>
</head>
<body>
<table border="1">
<tr>
<th>Product</th>
<th>Price Per Piece</th>
</tr>
<tr>
<td>Book</td>
<td>20</td>
</tr>
<tr>
<td>Pencil</td>
<td>10</td>
</tr>
<tr>
<td>Pen</td>
<td>5</td>
</tr>
</table>
<form method="POST"
action="fileread.php" >
<table border="1">
<tr>
<td>enter Your Name</td>
<td><input type="text"
name="cus_name"></td>
</tr>
<tr bgcolor="red">
<td
width="150">Product</td>
<td width="150">Name</td>
<td
width="70">Quantity</td>
</tr>
<tr>
<td width="150">Book</td>
<?php
$bookt=
array("computer","maths","science");
?>
<td width="150">
<select>
<?php
$length=count($bookt);
for($a=0;$a<$length;$a++)
{
?>
<option value=<?php $bookt[$a]; ?>>
<?php
if($a==0)
echo
"Computer";
if($a==1)
echo
"Science";
if($a==2)
echo
"Maths";
?>
</option>
<?php }
?>
</select>
</td>
<td width="70"><input
type="text" size="3" name="book"></td>
</tr>
<tr>
<td
width="150">Pencil</td>
<?php
$pencilt=
array("black","green","blue");
?>
<td width="150">
<select>
<option value=<?php $pencilt[0];
?>>Black </option>
<option value=<?php $pencilt[1];
?>>Green </option>
<option value=<?php $pencilt[2];
?>>Blue </option>
</select>
</td>
<td width="70"><input
type="text" size="3" name="pencil"></td>
</tr>
<tr>
<td width="150">Pen</td>
<?php
$pen=
array("black","green","blue");
?>
<td width="150">
<select>
<option value=<?php $pen[0];
?>>Black </option>
<option value=<?php $pen[1];
?>>Green </option>
<option value=<?php $pen[2];
?>>Blue</option>
</select>
<td width="70"><input
type="text" size="3" name="pen"></td>
</tr>
<tr>
<td width="150">How do you Find
Anika Stationary</td>
<td width="70">
<select name="find">
<option value="a">I am a regular
Customer</option>
<option value="b">TV
Advertising</option>
<option value="c">Phone
Directory</option>
<option value="d">Word of
mouth</option>
</select>
</td>
<tr>
<td>City</td>
<td>
<select name="city">
<option
value="a">Jaipur</option>
<option
value="a">Kota</option>
<option
value="a">Bundi</option>
</select>
</option>
</tr>
<tr colspan="2">
<td align="center"><input
type="submit" value="submit order"
name="submit"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$book=$_POST['book'];
$pencil=$_POST['pencil'];
$pen=$_POST['pen'];
$find=$_POST['find'];
}
?>
Ch-14 Array
<html>
<head>
<title>Book Store</title>
</head>
<body>
<table border="1">
<tr>
<th>Product</th>
<th>Price Per Piece</th>
</tr>
<tr>
<td>Book</td>
<td>20</td>
</tr>
<tr>
<td>Pencil</td>
<td>10</td>
</tr>
<tr>
<td>Pen</td>
<td>5</td>
</tr>
</table>
<form method="POST"
action="fileread.php" >
<table border="1">
<tr>
<td>enter Your Name</td>
<td><input type="text"
name="cus_name"></td>
</tr>
<tr bgcolor="red">
<td
width="150">Product</td>
<td width="150">Name</td>
<td
width="70">Quantity</td>
</tr>
<tr>
<td width="150">Book</td>
<?php
$bookt=
array("computer","maths","science");
?>
<td width="150">
<select>
<option value=<?php $bookt[0];
?>>Computer </option>
<option value=<?php $bookt[1];
?>>Maths </option>
<option value=<?php $bookt[2];
?>>Science </option>
</select>
</td>
<td width="70"><input
type="text" size="3" name="book"></td>
</tr>
<tr>
<td
width="150">Pencil</td>
<?php
$pencilt=
array("black","green","blue");
?>
<td width="150">
<select>
<option value=<?php $pencilt[0];
?>>Black </option>
<option value=<?php $pencilt[1];
?>>Green </option>
<option value=<?php $pencilt[2];
?>>Blue </option>
</select>
</td>
<td width="70"><input
type="text" size="3" name="pencil"></td>
</tr>
<tr>
<td width="150">Pen</td>
<?php
$pen=
array("black","green","blue");
?>
<td width="150">
<select>
<option value=<?php $pen[0];
?>>Black </option>
<option value=<?php $pen[1];
?>>Green </option>
<option value=<?php $pen[2];
?>>Blue</option>
</select>
<td width="70"><input
type="text" size="3" name="pen"></td>
</tr>
<tr>
<td width="150">How do you Find
Anika Stationary</td>
<td width="70">
<select name="find">
<option value="a">I am a regular
Customer</option>
<option value="b">TV
Advertising</option>
<option value="c">Phone
Directory</option>
<option value="d">Word of
mouth</option>
</select>
</td>
<tr>
<td>City</td>
<td>
<select name="city">
<option
value="a">Jaipur</option>
<option
value="a">Kota</option>
<option
value="a">Bundi</option>
</select>
</option>
</tr>
<tr colspan="2">
<td align="center"><input
type="submit" value="submit order"
name="submit"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$book=$_POST['book'];
$pencil=$_POST['pencil'];
$pen=$_POST['pen'];
$find=$_POST['find'];
}
?>
Ch-13 ftell(),fseek() and rewind () function
ftell() function is use to know pointer location.
fseek() set pointer at instructed location.
for example:
fseek($file,0)--> set pointer at begining.
fseek($file,5)--> set pointer at 5 location
<?php
$file=fopen("user.txt","r");
echo ftell($file);
fseek($file,5);
echo ftell($file);
?>
rewind() function set pointer at 0 location
<?php
$file=fopen("user.txt","r");
echo ftell($file);
rewind($file);
echo ftell($file);
?>
Monday, 23 December 2019
Ch-12 various read write File function
Create File in PHP
<html>
<head>
<title>Form Proceed</title>
<link rel ="stylesheet" href="order.css">
</head>
<body>
<h1>Anika Stationery</h1>
<h2>Order result</h2>
<?php
$book=$_POST['book'];
$pencil=$_POST['pencil'];
$pen=$_POST['pen'];
$find=$_POST['find'];
$name=$_POST['cus_name'];
echo "Welcome".$name;
switch($find)
{
case 'a':
echo "<br><mark>You are Regular Customer</mark>";
break;
case 'b':
echo "<br><span style='color:blue'>Customer Refer by TV advertisment</span>";
break;
case 'c':
echo "<p style='color:green'>Customer refered by Phone directory</p>";
break;
case 'd':
echo "<p>Customer refered by word of mouth</p>";
break;
}
echo "<br> order Proceed at ";
date_default_timezone_set('Asia/Kolkata');
echo date("l jS \of F Y h:i:s A");
echo "<br>Your Order List as follow:<br>";
echo "book: $book";
echo nl2br("\n pencil: $pencil");
echo "<br> pen: $pen<br>";
define('bookprice',20);
define('pencileprice',10);
define('penprice',5);
?>
<html>
<body >
<table border="1">
<tr>
<th>Product</th>
<th>Price Per Piece</th>
<th>Ordered Piece</th>
<th>Amount</th>
</tr>
<tr>
<td>Book</td>
<td>20</td>
<td><?php $book;
if($book==0)
{
echo "<font color='red'>";
echo 0;
echo "</font>";
}
else
echo $book;
?>
</td>
<td ><?php $cob=$book*bookprice;
if($cob==0)
{
echo "<font color='red'>";
echo $cob;
echo "</font>";
}
else
echo $cob;
?>
</td>
</tr>
<tr>
<td>Pencil</td>
<td>10</td>
<td><?php $pencil;
if($pencil==0)
{
echo "<font color='red'>";
echo 0;
echo "</font>";
}
else
echo $pencil;
?>
</td>
<td><?php $copncl=$pencil*pencileprice;
if($copncl==0)
{
echo "<font color='red'>";
echo $copncl;
echo "</font>";
}
else
echo $copncl;
?></td>
</tr>
<tr>
<td>Pen</td>
<td>5</td>
<td><?php $pen;
if($pen==0)
{
echo "<font color='red'>";
echo 0;
echo "</font>";
}
else
echo $pen;
?>
</td>
<td><?php $copn=$pen*penprice;
if($copn==0)
{
echo "<font color='red'>";
echo $copn;
echo "</font>";
}
else
echo $copn;
?></td>
</tr>
<?php
$total=$cob+$copncl+$copn;
if($total==0)
{
echo "<font color='red'>";
echo "you did not order anything ";
echo "<font>";
}
else
echo "<font color='blue'>";
echo "you ordered";
echo "</font>";
?>
<tr>
<td colspan="3">Sub Total Amount</td>
<td><?php echo $total; ?></td>
</tr>
<tr>
<?php
define('txt',0.10);
?>
<td colspan="3"> Total Amount with 10% tax</td>
<td><?php echo $total=$total*(1+ txt); ?></td>
</tr>
</table>
<?php
echo "<font color='red'>";
if ($total<100)
echo "There is no gift below Purchasing of Rs. 100 ";
elseif($total>=100 && $total<=300)
echo "You worth 50 of Rs. Voucher";
elseif($total>300)
echo "You worth of 100 Rs. Voucher";
echo "</font>";
$city=$_POST['city'];
if($city=="a")
echo "<br> You are from Jaipur City";
elseif($city=="b")
echo "<br> You are from Kota City";
elseif($city=="c")
echo "<br> You are from Bundi City";
?>
<form method="POST" action="distance.php">
<input type="submit" name="dis" value="Time chart">
<?php
if(isset($_POST['dis']))
{
?>
<a href="distance.php"></a>
<?php } ?>
<?php
$file=fopen("user.txt",'w');
fwrite($file,$name);
$text="------>";
fwrite($file,$text);
if($city=="a")
$cy="jaipur";
if($city=="b")
$cy="Kota";
if($city=="c")
$cy="Bundi";
fwrite($file,$cy);
?>
</body>
</html>
In place of last updated code , which colored by green , we change green color highlighted code by
<?php
$file=fopen("user.txt",'r');
echo fread($file,filesize("user.txt"));
fclose($file);
?>
for read data from file , but it does not show current data .
Pay Attention on below code , it's only read 5 byte of file
<?php
$file=fopen("user.txt",'r');
echo $re= fgets($file,5);
fclose($file);
below code is use to append or add new entry in end line in file.also create a new file if it does not exist.
<?php
$file=fopen("user.txt",'a');
$te="
";
fwrite($file,$te);
fwrite($file,$name);
fclose($file);
A+ code preserve previous content and add new one also at end of file .
<?php
$file=fopen("user.txt",'a+');
$te="
";
fwrite($file,$te);
fwrite($file,$name);
fclose($file);
r+ mode write data from begining of file also can read data in output
<?php
$file=fopen("user1.txt",'r+');
$te="
";
fwrite($file,$te);
fwrite($file,$name);
echo fread($file,filesize("user1.txt"));
fclose($file);
w+ is a read write mode. it
create a new file if it does not exist .
Also we have to use fseek() function between fwrite() and fread()
because fsesek() function e.g(fseel($file,0) set pointer at begining.
because fsesek() function e.g(fseel($file,0) set pointer at begining.
<?php
$file=fopen("user1.txt",'w+');
$te="
";
fwrite($file,$te);
fwrite($file,$name);
fseek($file, 0);
echo fread($file,filesize("user1.txt"));
fclose($file);
?>
You can add content in file by fputs() function
<?php
$file=fopen("user6.txt",'w');
$te="
";
fwrite($file,$te);
fwrite($file,$name);
fputs($file,"List of Customer");
fclose($file);
?>
Simmilarly X mod give false if file already exist. otherwise create new file and works only in write mode.
and
X+ mod give false if file already exist. otherwise create new file and works in read and write mode.
Subscribe to:
Posts (Atom)
-
<html> <head> <title>Book Store</title> </head> <body> <table border="1"...
-
old coding shows in yellow color updated coding shows in green color <html> <head> <title>Book Store</title...