You are on page 1of 36

Department of Computer Science

CSM-3371
SESSION 2021-22
3rd Semester
WEEK-9 and 10

Submitted by
Name: SHAHJAHAN
Roll no.: 20MCA25 Remark:
Enrolment no.:GI-1666
WEEK #9
1# Write a PHP program to connect to a database and retrieve data from a table
and show the details in a neat format
▪ Marklist of a student is entered and saved to MySQL table using PHP
▪ Data stored in MySQL table is displayed
Solution:
<?php include("username.php"?>

<!DOCTYPE html>

<html>

<head>
<title> User Name</title>

</head>

<body>

<h1>Registration Form & Enter Marks</h1>

<form action="" method="POST">

Enrollment No.:- <input type="text" name="enroll"><br><br> Student Name :-


<input type="text" name="name"><br><br> Class Name :- <input
type="text" name="class"><br><br> Email ID :- <input type="text"
name="email"><br><br> Physics :- <input type="number"
name="physics"><br><br>

Chemistry :- <input type="number" name="chemistry"><br><br> Mathematics :-


<input type="number" name="mathematics"><br><br> Hindi :-
<input type="number" name="hindi"><br><br>
English :- <input type="number" name="english"><br><br> Total :- <input
type="number" name="total"><br><br>
<input type="Submit" name="submit">

<style>
table, th, td {

border: 1px solid black; border-collapse: collapse;

th, td {padding: 5px;

th {

text-align:left;

</style>

</head>

<div class="col-lg-12">

<table class="table table-bordered">


<thead>

<tr>
<th>Name</th>

<th>Enrollment No.</th>

<th>Email ID</th>
<th>Class Name</th>
<th>Physics</th>
<th>Chemistry</th>

<th>Mathematics</th>

<th>Hindi</th>

<th>English</th>

<th>Total</th>

</tr>
</thead>

<tbody>
<?php

$dbhost='localhost';

$dbusername='root';
$dbpass='';

//$dbname='username'

$conn=mysqli_connect($dbhost,$dbusername,$dbpass,$dbname); if(!$conn) {
die("Connection Field" . $conn->connect_error);

$sql="select * from username";


$result=mysqli_query($conn,$sql); while($row=mysqli_fetch_assoc($result))

{
echo"<tr>";

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


$row["Enrollment_No"]; echo"</td>"; echo"<td>"; echo $row["Email_ID"];
echo"</td>"; echo"<td>"; echo $row["Class"]; echo"</td>"; echo"<td>"; echo
$row["Physics"]; echo"</td>"; echo"<td>"; echo $row["Chemistry"];
echo"</td>"; echo"<td>"; echo $row["Math"]; echo"</td>"; echo"<td>"; echo
$row["Hindi"]; echo"</td>"; echo"<td>"; echo $row["English"]; echo"</td>";
echo"<td>"; echo $row["Total"]; echo"</td>"; echo"</tr>";

}
mysqli_close($conn);

?>
</tbody>

</table>

</div>

<?php if(isset($_POST['submit']))
{
$enroll=$_POST['enroll'];

$name=$_POST['name'];

$class=$_POST['class'];
$email=$_POST['email'];

$physics=$_POST['physics'];

$chemistry=$_POST['chemistry'];
$mathematics=$_POST['mathematics'];

$english=$_POST['english'];
$hindi=$_POST['hindi'];

$total=$_POST['total'];

$result=mysqli_query($mysqli,"INSERT into username


values('$name','$enroll','$email','$class','$physics','$chemistry','$mathematics','$hin
di','$english','$total'
)");
if($result)

{
echo"<br>Registration Success";

else
{

echo"<br>Registration Not Success";


}

?>
<script type="text/javascript">

window.location.href=window.location.href;

</script>

</body>

</html>

Before Insert
After Insert
2# Write a PHP code to insert ,delete, select the data from database

<?php include("username.php")

?>

<!DOCTYPE html>

<html>

<head>

<title> User Name</title>

</head>

<body>

<h1>Registration Form & Enter Marks</h1>

<form action="" method="POST">

Enrollment No.:- <input type="text" name="enroll"><br><br> Student Name :-

<input type="text" name="name"><br><br> Class Name :- <input

type="text" name="class"><br><br> Email ID :- <input type="text"

name="email"><br><br> Physics :- <input type="number"

name="physics"><br><br>

Chemistry :- <input type="number" name="chemistry"><br><br> Mathematics :-

<input type="number" name="mathematics"><br><br> Hindi :-

<input type="number" name="hindi"><br><br>

English :- <input type="number" name="english"><br><br> Total :- <input

type="number" name="total"><br><br>
<input type="Submit" name="submit">

<button type="Submit" name="delete">Delete</button>

<button type="Submit" name="update">Update</button><br><br>

<style>

table, th, td {

border: 1px solid black; border-collapse: collapse;

th, td {

padding: 5px;

th {

text-align:left;

}
</style>

</head>

<div class="col-lg-12">

<table class="table table-bordered">

<thead>

<tr>

<th>Name</th>

<th>Enrollment No.</th>
<th>Email ID</th>

<th>Class Name</th>

<th>Physics</th>

<th>Chemistry</th>

<th>Mathematics</th>

<th>Hindi</th>

<th>English</th>

<th>Total</th>

</tr>

</thead>

<tbody>

<?php

$dbhost='localhost';

$dbusername='root';

$dbpass='';

//$dbname='username'
$conn=mysqli_connect($dbhost,$dbusername,$dbpass,$dbname); if(!$conn) {

die("Connection Field" . $conn->connect_error);

$sql="select * from username";

$result=mysqli_query($conn,$sql); while($row=mysqli_fetch_assoc($result))

{
echo"<tr>";

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

$row["Enrollment_No"]; echo"</td>"; echo"<td>"; echo $row["Email_ID"];

echo"</td>"; echo"<td>"; echo $row["Class"]; echo"</td>"; echo"<td>"; echo

$row["Physics"]; echo"</td>"; echo"<td>"; echo $row["Chemistry"];

echo"</td>"; echo"<td>"; echo $row["Math"]; echo"</td>"; echo"<td>"; echo

$row["Hindi"]; echo"</td>"; echo"<td>"; echo $row["English"]; echo"</td>";

echo"<td>"; echo $row["Total"]; echo"</td>"; echo"</tr>";


}

mysqli_close($conn);

?>

</tbody>

</table>
</div>

<?php if(isset($_POST['submit']))

$enroll=$_POST['enroll'];

$name=$_POST['name'];

$class=$_POST['class'];

$email=$_POST['email'];

$physics=$_POST['physics'];

$chemistry=$_POST['chemistry'];
$mathematics=$_POST['mathematics'];

$english=$_POST['english'];

$hindi=$_POST['hindi'];

$total=$_POST['total'];

$result=mysqli_query($mysqli,"INSERT into username


values('$name','$enroll','$email','$class','$physics','$chemistry','$mathematics','$hin
di','$english','$total'
)");

if($result)

echo"<br>Registration Success";

else

echo"<br>Registration Not Success";

}
}

?>

<script type="text/javascript"> window.location.href=window.location.href;

<?php if(isset($_POST['delete']))

mysqli_query($mysqli,"Delete from username where Total='$_POST[total]'

"); echo"success";
}

?>

<script type="text/javascript"> window.location.href=window.location.href;

</script>

<?php if(isset($_POST['update']))

mysqli_query($mysqli,"Update username SET


Enrollment_No='$_POST[enroll]' where Name
='$_POST[name]'");

?>

<script type="text/javascript"> window.location.href=window.location.href;

</script>

</body>
</html>

Another File

<?php

$dbhost='localhost';

$dbname='username';

$dbusername='root';

$dbpass='';
$mysqli=mysqli_connect($dbhost,$dbusername,$dbpass,$dbname);

?>
Before Updation

After Updation
Before Deletion
After Deletion

3# Write a PHP code to create database & table in Mysql.

<?php

?>

<?php
$dbhost='localhost';

$dbusername='root';

$dbpass='';

$conn=mysqli_connect($dbhost,$dbusername,$dbpass); if(!$conn) {

die("Connection Field:" . mysqli_connect_error());

$sql="CREATE DATABASE username"; if(mysqli_query($conn, $sql)) {

echo "<br>Database created successfully with the name Username";

else

echo"<br>Error creating database: " . mysqli_error($conn);

$dbname='username';

$conn1=mysqli_connect($dbhost,$dbusername,$dbpass,$dbname);

$res = "CREATE TABLE username(Name varchar(20), Enrollment_No


varchar(20), Email_ID varchar(45), Class varchar(20), Physics INT(10), Chemistry
INT(10), Math int(10), Hindi int(10), English int(10), Total int(10) )";
if(mysqli_query($conn1, $res)){

echo "<br>Table created successfully.";

} else{

echo "<br>ERROR: Could not able to execute $sql. " .


mysqli_error($conn1);

mysql_close($conn); mysql_close($conn1);

?>
WEEK 10

Problems Based on ASP.NET Programming

1# Develop an application which is similar to notepad using menus.

Code:
1. Create a new Window application with name as notepad
2. Add Menu Strip to form1 and set IsMdiContainer property of form1 to
true
3. Set text property of form1 as Notepad
4. Create File menu by adding text at type here textbox.
(File,New ,Open,save,Exit)
5. Create Edit menu by adding text at type here textbox.
(Edit,cut,Copy,Paste,Select
All,Time/date,Clear)
6. Create Format menu by adding text at type here textbox.(Format,font)
7. Add Form2 tp project by clicking Project menu.
8. Add Richtextbox to form2 and set dock property of richtextbox to fill.
9. Add the following code by double clicking File-New Option in
menustrip.
10. Add OpenfileDialog,SaveFileDialog,FontDialog to form1.
Public Class Form1
Public Class Form1
Dim n As Integer
Dim forms(10) As Form2
Dim s As String
Dim s1 As Integer
Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles NewToolStripMenuItem.Click
n += 1
forms(n) = New Form2

forms(n).Text = "Unititled document" & Str(n)


forms(n).MdiParent = Me
forms(n).Show()
End Sub
////// Double click on File-Open option in menu Strip and add the code.
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
OpenFileDialog1.Filter = "txtfile(*.txt*)|*.txt*"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
forms(n).Show()
forms(n).RichTextBox1.Text =
My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
forms(n).Text = OpenFileDialog1.FileName
End If End Sub
////// Double click on File-Save option in menu Strip and add the code.
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles SaveToolStripMenuItem.Click s = forms(n).RichTextBox1.Text
SaveFileDialog1.Filter = "txtfiles(*.txt*)|*.txt*" SaveFileDialog1.Title = "save
"
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, s, True)
forms(n).Text = SaveFileDialog1.FileName
forms(n).RichTextBox1.Text = s
End If End Sub
////// Double click on File-Close option in menu Strip and add the code.
Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
End End Sub
////// Double click on Edit-Cut option in menu Strip and add the code.

Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs)
Handles CutToolStripMenuItem.Click forms(n).RichTextBox1.Select()
forms(n).RichTextBox1.Cut()
End Sub

////// Double click on Edit-Copy option in menu Strip and add the code.

Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs)
Handles CopyToolStripMenuItem.Click forms(n).RichTextBox1.Select()
forms(n).RichTextBox1.Copy()
End Sub

////// Double click on Edit-Paste option in menu Strip and add the code.

Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click
forms(n).RichTextBox1.Paste() End Sub
////// Double click on Edit-SelectAll option in menu Strip and add the code.

Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
SelectAllToolStripMenuItem.Click
forms(n).RichTextBox1.SelectAll()
End Sub
////// Double click on Edit-Clear option in menu Strip and add the code.
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
forms(n).RichTextBox1.Clear() End Sub
////// Double click on Edit-Time/Date option in menu Strip and add the code.

Private Sub TimedateToolStripMenuItem_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
TimedateToolStripMenuItem.Click
forms(n).RichTextBox1.Text = Date.Today.ToString End Sub
////// Double click on Format-Font option in menu Strip and add the code.

Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
forms(n).RichTextBox1.ForeColor = FontDialog1.Color
forms(n).RichTextBox1.Font = FontDialog1.Font
End If
End Sub
End Class
Design:
Title of the form:
Notepad Controls used:

Control Name Caption


Form1 Notepad
Form2 Form2
MenuStrip Menustrip1
OpenFileDialog OpenFileDialog1
SaveFileDialog SaveFileDialog1
FontDialog FontDialog1
Richtextbox1 Richtextbox1
OUTPUT:

2# (a) Develop an application for facilitating purchasing order .


Code: Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles MyBase.Load cmb_cars.Items.Add("car1")
cmb_cars.Items.Add("car2")
cmb_cars.Items.Add("car3")
cmb_cars.Text = "Select One"
End Sub

Private Sub cmb_cars_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs)
Handles Cmb_cars.SelectedIndexChanged
lst_model.Items.Clear()
txt_price.Clear()
cmb_colors.Items.Clear()
cmb_colors.Text = "select One"
Dim str As String = cmb_cars.SelectedItem.ToString()
MsgBox(str)
If str = "car1" Then cmb_colors.Items.Add("red")
cmb_colors.Items.Add("blue") cmb_colors.Items.Add("Black")
lst_model.Items.Add("Model1") lst_model.Items.Add("Model2")
lst_model.Items.Add("Model3")
ElseIf cmb_cars.SelectedItem.ToString() = "car2" Then
cmb_colors.Items.Add("White")
cmb_colors.Items.Add("Silver")
cmb_colors.Items.Add("Black")
lst_model.Items.Add("Model4")
lst_model.Items.Add("Model5") l
st_model.Items.Add("Model6")
ElseIf cmb_cars.SelectedItem.ToString() = "car3"
Then cmb_colors.Items.Add("Darkgreen")
cmb_colors.Items.Add("green") cmb_colors.Items.Add("Black")
lst_model.Items.Add("Model7") lst_model.Items.Add("Model8")
lst_model.Items.Add("Model9")
End If End Sub
Private Sub lst_model_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lst_model.SelectedIndexChanged
Dim str As String = lst_model.SelectedItem.ToString()

If str = "Model1" Or str = "Model4" Or str = "Model7" Then txt_price.Text =


"4,00000"
ElseIf str = "Model2" Or str = "Model5" Or str = "Model8" Then txt_price.Text
= "3,50000"
ElseIf str = "Model3" Or str = "Model6" Or str = "Model9" Then txt_price.Text
= "6,00000"
End If End Sub
Private Sub btn_purchase_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_purchase.Click
MessageBox.Show("Thank for purchasing" &
Cmb_cars.SelectedItem.ToString())
End Sub
End Class Design:
Title of the form: Purchase Car Controls used:
Control Name Text
Form1 form1 Purchase car
Label1 lbl_title Purchase car
Label2 lbl_cars Cars
Label3 lbl_colors Colors
Label4 lbl_model Model
Label5 lbl_price Price in Rs
Button1 btn_purchase Purchase
Button2 btn_cancel Cancel
Combobox1 cmb_cars Select one
Combobox2 cmb_colors Select One
List box lst_model
Textbox1 txt_price
OUTPUT:

b). Develop an application for billing system in coffee shop


Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lbl_cardno.Visible = False txt_card.Visible = False
End Sub
Private Sub btn_calculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_calculate.Click
Dim ws, wos, cc, hc, tc, tt, tot As Integer ws = 5
wos = 8
cc = 20
hc = 10
If chk_tea.Checked = True Then tt = txt_tea.Text * wos
ElseIf chk_tea.Checked = False Then tt = txt_tea.Text * ws
End If
If chk_coffee.Checked = True Then tc = txt_coffee.Text * cc
ElseIf chk_coffee.Checked = False Then tc = txt_coffee.Text * hc
End If
tot = tt + tc
If rdo_cash.Checked = True Then txt_amt.Text = tot
MsgBox("Payment received in Cash!Thank U u select" & chk_tea.Text & "and
" & chk_coffee.Text)
ElseIf rdo_card.Checked = True Then If txt_card.Text = "" Then
MsgBox("U must enter pin number") txt_card.Focus()
Else

txt_card.Text = tot
MsgBox("Payment is deduced from ur account") End If
ElseIf rdo_cash.Checked = False And Rdo_card.Checked = False Then
MsgBox("U must choose payment mode")
End If End Sub
Private Sub rdo_card_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rdo_card.CheckedChanged
lbl_cardno.Visible = True txt_card.Visible = True
End Sub
Private Sub btn_close_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_close.Click
Me.Close()
End Sub
End Class
Design:
Title of the form: Cafeteria Controls used
Control Name Text
Form1 Form1 Cafeteria
Label1 lbl_tea Tea
Label2 lbl_coffee Coffee
Label3 lbl_total Total amount in RS
Label4 lbl_cardno Enter card No
Label5 lbl_qty Qty
Button1 btn_calculate Calculate
Button2 btn_close Close
Textbox1 txt_tea
Textbox2 txt_coffee
Textbox3 txt_amt
Textbox4 txt_card
Check box1 chk_tea Without sugar
CheckBox2 chk_coffee Cold coffee
Radio Button1 rdo_cash Cash
RadioButtton2 rdo_card Crdit card
GroupBox1
GroupBox2
OUTPUT:

2# Develop an application using tree view control.

1. Create a window application and named it as Tree View

2. Add Two labels and tree view control to form1

3. Set
the text property of label1 as Select the formatting option and label2 as
Welcome.
4. In
the properties window click on ellipse button beside the nodes option.
This will open a tree node Editor dialog box.

5. Click on Add Root Button.

6. Type the text options in the text property. This will set the text of the node
to options.

7. Now select the option node and click on Add Child button to add child
nodes to the parent node Options.

8. Now set the text property of node as Size and add another chilld Format

9. Now add child nodes to size and Format and click ok button.

Double click on tree view and add following code.


Public Class Form1
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.TreeViewEventArgs) Handles
TreeView1.AfterSelect
If (e.Node.Text = "Small") Then

lbl_text.Font = New Font(lbl_text.Font.Name, 10, lbl_text.Font.Style) End If


If (e.Node.Text = "Large") Then

lbl_text.Font = New Font(lbl_text.Font.Name, 20, lbl_text.Font.Style) End If


If (e.Node.Text = "Bold") Then

lbl_text.Font = New Font(lbl_text.Font.Name, 15, FontStyle.Bold) End If


If (e.Node.Text = "Small") Then
lbl_text.Font = New Font(lbl_text.Font.Name, 15, FontStyle.Italic) End If
End Sub End Class
Design:
Title of the form:
Tree View Control Controls used

Control Name Caption


Form1 Tree View
Tree view Tree View1
Label1 Lbl_title Select the formatting option
Label2 Lbl_text Welcome
OUTPUT:

3# Develop an application to display the file selected by the user in a web


browser control.

Public Class Form1


Private Sub btn_add_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_add.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
lst_items.Items.Add(OpenFileDialog1.FileName)
End If End Sub
Private Sub btn_load_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_load.Click
Dim s As String
s = lst_items.SelectedItem MsgBox(s) WebBrowser1.Navigate(s)
End Sub

Private Sub btn_scroll_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btn_scroll.Click
WebBrowser1.ScrollBarsEnabled = True End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
WebBrowser1.ScrollBarsEnabled = False

End Sub End Class


Design:
Title of the form: Web Browser Control Controls used:
Control Name Text
Form1 Form1 Web Browser
List Box1 lst_items
Button1 btn_add Add Items to list
Button2 btn_load Load Files
Button3 btn_scroll Show Scroll Bars
Open FileDailog open File Dialog1
Web Browser Control Web Browser1
OUTPUT:

You might also like