Space for google add

Use of explode function in PHP .

 


Write a PHP script for the following: Design a form to accept the details of 5 different items, such as item code, item name, units sold, rate. Display the bill in the tabular format. Use only 4 text boxes. (Hint : Use of explode function.)


a1setc1.html

<html>

<body>

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

Enter Item Code :

<input type="text" name="code" value=" "><br>

Enter Item Name :

<input type="text" name="name" value=" "><br>

Enter Units Sold  :

<input type="text" name="sold" value=" "><br>

Enter Item rate:

<input type="text" name="rate" value=" "><br>

<input type='submit' name='submit' value='submit'>

</form>

</body>

</html>



a1setc1.php

<?php

$c=$_POST['code'];

$n=$_POST['name'];

$s=$_POST['sold'];

$r=$_POST['rate'];

$code=explode(" ",$c);

$name=explode(" ",$n);

$sold=explode(" ",$s);

$rate=explode(" ",$r);

echo "<table border=2>";

echo "<tr><th>Item Code<th>Item Name<th>Units Sold<th>Item Rate</th></tr>";

$sum=0.0;

for($i=0;$i<count($rate);$i++)

{

echo "<tr>";

echo "<td>$code[$i]</td>";

echo "<td>$name[$i]</td>";

echo "<td>$sold[$i]</td>";

echo "<td>$rate[$i]</td>";

echo "</tr>";

$sum=$sum+($sold[$i]*$rate[$i]);

}

echo "Total Bill :$sum";

?>


Post a Comment

0 Comments