Slip 15 - C) Write PHP program to create input form for Grocery that displays List of grocery items with checkboxes and create a bill according to list of items selected after clicking submit button.

Solution:

slip15.html


<!DOCTYPE html>

<html>

  <body>

    <form action="slip15.php" method="GET">

      Please select your gelosery<br />

 

      <input type="checkbox" name="check_b[]" value="rice" />Rice<br />

      <input type="checkbox" name="check_b[]" value="oils" />Oils<br />

      <input type="checkbox" name="check_b[]" value="milk" />Milk<br />

      <input type="checkbox" name="check_b[]" value="bread" />Bread<br />

      <input type="submit" value="sumbit" />

    </form>

  </body>

</html>

 

 slip15.php


<?php

$hostname="127.0.0.1";

$db_name="grecery";

$username="root";

$password="";

$connection=mysqli_connect("$hostname","$username","$password","$db_name")or

die("unable to connect");

if(!$connection){

    echo"Error:Unable to connect to MySQL.<br>";

    echo"<br>Debugging errno: ".mysqli_connect_errno();

    echo"<br>Debugging errno: ".mysqli_connect_errno();

    exit;

 

}

if($stmt =$connection->query("SELECT * FROM `bill` ")){

    echo "<table border='2'>";

    echo "<tr><td>sr.no</td><td>Name Item</td><td>Quntity</td><td>Rate</td><td>Amount</td></tr>";

    while($row=$stmt->fetch_assoc()){

    echo "<tr><td>".$row['s.no']."</td>";

    echo"<td>". $row['Name Item']."</td>";

    echo "<td>".$row['Quntity']."</td>";

    echo "<td>".$row['Rate']."</td>";

    echo "<td>".$row['Amount']."</td></tr>";

 

}

echo "</table>";



 

}

?>

 

phpmyadmin create database:


step1:chrome type localhost/phpmyadmin

step2: create new database "grecery"

CREATE TABLE `bill` (

  `s.no` int(11) NOT NULL,

  `Name Item` varchar(11) NOT NULL,

  `Quntity` int(11) NOT NULL,

  `Rate` int(11) NOT NULL,

  `Amount` int(11) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;



INSERT INTO `bill` (`s.no`, `Name Item`, `Quntity`, `Rate`, `Amount`) VALUES

(1, 'Rice', 670, 35, 3500),

(2, 'Oils', 345, 120, 12222);

ALTER TABLE `bill`

  ADD PRIMARY KEY (`s.no`);



ALTER TABLE `bill`

  MODIFY `s.no` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

COMMIT;

Post a Comment

0 Comments