0% found this document useful (0 votes)
121 views26 pages

Output

This document contains questions and answers related to various HTML tags. It begins with questions about adding tooltips, changing image size and dimensions, creating links, adding headings, and modifying text colors and styles. Later questions cover using additional tags like <abbr>, <q>, <blockquote>, <pre>, lists, and applying CSS and JavaScript validation to a registration form. The document provides code snippets and expected outputs for each task.

Uploaded by

Patel Bansari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views26 pages

Output

This document contains questions and answers related to various HTML tags. It begins with questions about adding tooltips, changing image size and dimensions, creating links, adding headings, and modifying text colors and styles. Later questions cover using additional tags like <abbr>, <q>, <blockquote>, <pre>, lists, and applying CSS and JavaScript validation to a registration form. The document provides code snippets and expected outputs for each task.

Uploaded by

Patel Bansari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Web Programming (PS02CINT24)

Q1(1) Add tooltip to the paragraph with that “About IT Course”.


<html>
<head>
<title>About IT Course</title>
</head>
<body>
<h1><center>About IT Course</h1></center>
<p title="Hyper Text Markup Language"
align=”center”>HTML</p>
</body>
</html>
OUTPUT:-

Q1(2) Changed size of the image to 250 width and 400 height.
<html>
<head>
<title>Image Size</title>
</head>
<body><img src="image1.jpeg" width=”250” height=”400”></image></body>
</html>
OUTPUT:-

Q1(3) Transform the text “click here into a link that goes to
www.google.com”.
<html>
<head></head>
<body>
<h1><center><a
href="www.google.com">ClickToRedirect</a></center></h1>
</body>
</html>
OUTPUT:-

Q1(4) The image number 2 does not exists. Specify the alternate text
“istar.edu.in” for the image.
<html>
<head><title>Image Size</title></head>
<body><image src="img" width=250 height=400 alt="istar.edu.in"></image>

Prepared By: Chirag Parmar(IT1805) 1


Web Programming (PS02CINT24)

</body>
</html>
OUTPUT:-

Q1(5) Image as a link.


<html>
<head><title>Image Size</title></head>
<body>
<a href="Q1(1).html"><imag src="i1.jpeg" width=250
height=400></a></image>
</body>
</html>
OUTPUT:-

Q1(6) Add 6 headings to the documents “ISTAR”.


<html>
<head></head>
<body>
<h1>ISTAR</h1>
<h2>ISTAR</h2>
<h3>ISTAR</h3>
<h4>ISTAR</h4>
<h5>ISTAR</h5>
<h6>ISTAR</h6>
</body>
</html>
OUTPUT:-

Prepared By: Chirag Parmar(IT1805) 2


Web Programming (PS02CINT24)

Q1(7) Changed the text color of the paragraph to red.


<html>
<head><title>About IT Course</title></head>
<body>
<h1><center>About IT Course</h1></center>
<p title="About IT courses"><font color="RED">Html also known as Hyper Text
Markup Language. It is A scripting Language</p></font>
</body>
</html>
OUTPUT:-

Q1(8) Changed background color of page.


<html>
<head></head>
<body bgcolor="blue"><P>This is blue color page </p>
</body>
</html>
OUTPUT:-
This is blue color page

Q1(9) Use an elements to aim around the letters “HTML”.


<html>
<head></head>
<body>
<q>HTML</q>
</body>
</html>
OUTPUT:-

Prepared By: Chirag Parmar(IT1805) 3


Web Programming (PS02CINT24)

Q1(10) The letters html in the text below is an abbreviation of hypertext


markup language.
<html>
<head></head>
<body>
<h1><center><abbrtitle="Cascading Style
Sheet">Css</abbr></h1></center >
</body>
</html>
OUTPUT:-

Q2 To create a simple html file to demonstrate the use of different tags.


a) Moving text = “Simple HTML Tags”
b) Different heading tags ( h1 to h6)
c) Paragraph
d) Horizontal line
e) Line Break
f) Block Quote
g) Pre tag
h) Different Logical Style (<b>,<c>,<sub>,<sup>…)
i) Different Physical Style(<code>,<del>…)
j) Listing Tags
<html>
<body><center>
<marquee>"Simple html tag"</marquee>
<h1>Hello</h1>
<h2>Hello</h2>
<h3>Hello</h3>
<h4>Hello</h4>
<h5>Hello</h5>
<h6>Hello</h6>
<p>This is some text in a paragraph.ISTAR</p>
<hr>
<h1>HTML</h1>
<p>HTML is a language for describing web pages.....</p>
<hr>
<p>Hello</br>Chirag</p>
<Q>HTML is scripting language</Q>
<pre>Text in a pre element is displayed in a fixed-width font, and it
preserves both spaces and line breaks

Prepared By: Chirag Parmar(IT1805) 4


Web Programming (PS02CINT24)

</pre>
<p>My favorite color is <del>blue</del><ins>red</ins>!</p>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<p>This text contains <sup>superscript</sup> text.</p></center>
</body>
</html>
OUTPUT:-

Q3 (a)Creating a form registeryourself.html using HTML tags.


(b) Cascading Style Sheets (CSS): Apply Style Sheet on
registeryourself.html

Prepared By: Chirag Parmar(IT1805) 5


Web Programming (PS02CINT24)

(c) JavaScript: Form Validation – Validating form


registeryourself.html using functions and events
<html>
<head><title>Registration Form</title></head>
<body>
<form>
<table border="1" align="center">
<tr>
<td><img src="E:\chirag\Picture2.png"></img></td>
<td align=center>INSTITUTE OF SCIENCE & TECHNOLOGY<br>
FOR ADVANCED STUDIES & RESEARCH</td>
</tr>
<tr align=center>
<td colspan=2><h1>MSC IT</h1></td>
</tr>
<tr align=center>
<td colspan=2><h1><marquee onmouseover="this.stop();"
onmouseout="this.start();">Registration
Form</h1></marquee></td>
</tr>
<tr>
<td align=center>First Name :</td>
<td><input type="text" name="firstname"></td>
</tr>
<tr>
<td align=center>Middle Name :</td>
<td><input type="text" name="middlename"></td>
</tr>
<tr>
<td align=center>Last Name :</td>
<td><input type="text" name="lastname"></td>
</tr>
<tr>
<td align=center>Address :</td>
<td><textarea rows="5" cols="40"></textarea></td>
</tr>
<tr>
<td align=center>Mobile number :</td>
<td><input type="text" name="mobilenumber"
maxlength=10></td>
</tr>
<td align=center>Email Id :</td>
<td><input type="text" name="emailid"></td>
</tr>
<tr>
<td align=center>Gender :</td>
<td><input type=radio name="male" checked>Male<br>
<input type=radio name="male" >Female</td>
</tr>
<tr>
<td align=center>Date of Birth :</td>
<td><input type="date" name="bdate"></td>
</tr>
<tr>

Prepared By: Chirag Parmar(IT1805) 6


Web Programming (PS02CINT24)

<td align=center>Hobbies :</td>


<td><select>
<option value="Drawing">Drawing</option>
<option value="Singing">Singing</option>
<option value="GYM">GYM</option>
<option value="Playing">Playing</option>
<option value="Swimming">Swimming</option>
</select>
</td>
</tr>
<tr>
<td align=center>Father's Name :</td>
<td><input type="text" name="fathername"></td>
</tr>
<tr>
<td align=center>Mother's Name :</td>
<td><input type="text" name="firstname"></td>
</tr>
<tr>
<td align=center>Father's Occupation :</td>
<td><input type="text" name="firstname"></td>
</tr>
<tr>
<td align=center>Mother's Occupation :</td>
<td><input type="text" name="firstname"></td>
</tr>
<tr>
<td colspan=2 align=center><input type="submit"
value="submit">
<input type="reset" value="reset">
</td>
</tr>
</table>
</form>
</body>
</html>
OUTPUT:-

Q4 Show the use of events to change background color with HTML and
JavaScript.
 If mouse button is pressed, background color should be red.
 If mouse button is released up, background color should be

Prepared By: Chirag Parmar(IT1805) 7


Web Programming (PS02CINT24)

yellow.
<html>
<head>
<script type="text/javascript">
function f1()
{
document.body.style.background="red";
}
function blur()
{
document.body.style.background="yellow";
}
</script>
</head>
<body>
<form><center><input type="button" value="Click Me" onclick="f1()"
onblur="blur()" ></center>
</form>
</body>
</html>
OUTPUT:-

Q5 Develop and demonstrate a XHTML file that includes Javascript script


for the following problems:
a) Input : A number n obtained using prompt
Output : The first n Fibonacci numbers
<html>
<head>
<script type=”text/javscript”>
function getvalue()
{
var value=prompt("enter the value","Enter The Value");
var x=0;
var y=1;
var z;
document.write("Fibonacci Series = "+x," ");
document.write(+y);
for(i=0;i<=value-3;i++)
{
z=x+y;
document.write(" ",z," ")
x=y;
y=z;
}
}
</script>
</head>

Prepared By: Chirag Parmar(IT1805) 8


Web Programming (PS02CINT24)

<body>
<form>
<input type="button" value="click" onclick="getvalue()" />
</form>
</body>
<html>
OUTPUT:-

Q6 Write a program to Show use of alert, confirm and prompt box.


<html>
<head>
<script type=”text/javascript”>
function warn()
{
alert("This is a warning msg");
}
function getConform()
{
var retVal = confirm("Do you want exit");
if( retVal == true)
{
alert("user continue");
}
else
{
alert("user does not continue");
}
}
function getprompt()
{
var retVal = prompt("enter the no","enter the no");
document.write("Welcome " +retVal);
}
</script>
</head>
<body>
<form><center>
<input type="button" value="alert" onclick="warn()" />

Prepared By: Chirag Parmar(IT1805) 9


Web Programming (PS02CINT24)

<input type="button" value="conform" onclick="getConform()" />


<input type="button" value="promopt" onclick="getprompt()"
/></center>
</form>
</body>
</html>
OUTPUT:-

Q7 To display the square of a given numbers using Javascript


<html>
<head>
<script type="text/javascript">
function sqaure()
{
var n=prompt("Enter the value","");
var msg="";
var sqr="0";
for(var x=1;x<=n;x++)
{
sqr=x*x;
msg+=x+"*"+x+"="+sqr+"\n";
}
alert("Sqaure of number:"+"\n"+msg);
}
</script>
</head>
<body>
<form>

Prepared By: Chirag Parmar(IT1805) 10


Web Programming (PS02CINT24)

<input type="button" value="Answer" onclick="sqaure()">


</form>
</body>
</html>
OUTPUT:-

Q8 Implement all methods of creating 1D, 2D and multidimensional array.


<?php
$number=array(1,2,3,4,5,);
foreach($number as $value)
{
echo "value is $value"."<br>";
}
$salaries = array("akash"=>2000,"mahesh"=>1000,"dhaval"=>500);
echo "Salary of akash is".$salaries['akash']."<br>";
echo "Salary of mahesh is".$salaries['mahesh']."<br>";
echo "Salary of dhaval is".$salaries['dhaval']."<br>";
$marks=array(
"akash"=>array(
"php"=>75,
".net"=>85,
"c++"=>65),
"mahesh"=>array(
"php"=>60,
".net"=>55,
"c++"=>45),

Prepared By: Chirag Parmar(IT1805) 11


Web Programming (PS02CINT24)

"dhaval"=>array(
"php"=>85,
".net"=>65,
"c++"=>61));

echo "marks of akash in php:";


echo $marks['akash']['php']."<br>";
echo "marks of mahesh in .net";
echo $marks['mahesh']['.net']."<br>";
echo "marks of dhaval in c++";
echo $marks['dhaval']['c++']."<br>";
?>
OUTPUT:-

Q9 Write a program to print below format


1
12
123
1234
12345
123456
1234567
12345678
<?php
for($i=1;$i<=8;$i++)
{
for($j=1;$j<=$i;$j++){
echo $j." ";
}echo "<br>";
}
?>
OUTPUT:-

Prepared By: Chirag Parmar(IT1805) 12


Web Programming (PS02CINT24)

Q10 Display “Welcome to ISTAR” five times


<?php
$name = "Welcome to ISTAR";

for($i=0;$i<=4;$i++)
{
echo $name."<br>";
}
?>
OUTPUT:-

Q11 Write a program to show data types in php.


<?php
error_reporting(0);
$a = 12;
$b = 12.45;
$c = "Istar";
$d = true;
$e = null;
$f = array("1"=>"istar", "n"=>"nvpas");
var_dump($a);
var_dump($b);
var_dump($c);
var_dump($d);
var_dump($e);
var_dump($f);
?>
OUTPUT:-

Q12 Find sum of given two number using function.


<html>
<head>
</head>
<body>

Prepared By: Chirag Parmar(IT1805) 13


Web Programming (PS02CINT24)

<form method="POST">
Enter number 1:-<input type="number" name="n1"><br>
Enter number 2:-<input type="number" name="n2"></br><input
type="submit" name="submit" value="add">
</form>
</body>
</html>
<?php
function addfunction($num1,$num2)
{
$sum=$num1+$num2;
echo"Sum of two numbers is:-",$sum;
}
if(isset($_POST["submit"]))
{
$a=$_POST['n1'];
$b=$_POST['n2'];
addfunction($a,$b);
}
?>
OUTPUT:-

Q13 Perform arithmetic operation using switch case construct


<html>
<head>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
if(is_numeric($_POST['number1'])&&is_numeric($_POST['number2']))
{
switch($_POST['n1'])
{
case 1: $total = $_POST['number1'] + $_POST['number2'];
break;
case 2:$total = $_POST['number1'] - $_POST['number2'];
break;
case 3:$total = $_POST['number1'] * $_POST['number2'];
break;
case 4:$total = $_POST['number1'] / $_POST['number2'];
break;
case 5:$total = $_POST['number1'] % $_POST['number2'];
break;
default:
echo "Please Enter valid option";
break;
}

Prepared By: Chirag Parmar(IT1805) 14


Web Programming (PS02CINT24)

}
else
{
echo "Enter valid number";
}
}
?>
<form method="POST">
<table border=0 align="center">
<tr align="center">
<td><h1>ARITHMATIC OPERATOR</h1></td>
</tr>
<tr>
<td>number1:<input type="text" name="number1">
number2:<input type="text" name="number2">
<hr>
1. Addition</br>
2. Subtraction</br>
3. Multiplication</br>
4. Division</br>
5. Modulus</br>
</hr>
Enter your choice</br><input type="n1" type="text" style="display: inline" />
<input name="submit" type="submit" value="Calculate"/>
</td>
</tr>
<tr>
<td align="center">Answer:<input type="text" name="result" value="<?php
echo @$total ?>" disable></td>
</tr>
</table>
</form>
</body>
</html>
OUTPUT:-

Q14 Display your name n times. Take the input through text box.
<html>
<body>
<form method ="POST">

Prepared By: Chirag Parmar(IT1805) 15


Web Programming (PS02CINT24)

<table>
<tr>
enter your name:</br>
<input type = "text" name = "name"></br>
</tr>
<tr>
print:<input type = "text" name = "t1"></br>
</tr>
<input type = "submit" name = "submit" value = "submit">
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$t2 = $_POST['t1'];
}
for($i = 1;$i <=$t2; $i++)
{
echo $name;
echo "<br>";
}
?>
</body>
</html>
OUTPUT:-

Q15 Write HTML and PHP script to check whether given number is odd or
even. Take the input through text box.
<html>
<head>
</head>
<body>
<form method="POST">
Enter number:-<input type="number" name="n1"><br>
<input type="submit" name="submit" value="add">
</form>
</body>
</html>
<?php
if(isset($_POST["submit"]))
{
$a=$_POST['n1'];
if($a%2==0)
{
echo"Number $a is even";

Prepared By: Chirag Parmar(IT1805) 16


Web Programming (PS02CINT24)

}
else
{
echo"Number $a is odd";
}
}
?>
OUTPUT:-

Q16 Design Calculator.


<html>
<head></head>
<body>
<?php
if(isset($_POST['submit']))
{
if(is_numeric($_POST['number1']) && is_numeric($_POST['number2']))
{
if($_POST['operation'] == 'plus')
{
$total=$_POST['number1']+$_POST['number2'];
}
if($_POST['operation'] == 'minus')
{
$total = $_POST['number1'] - $_POST['number2'];
}
if($_POST['operation'] == 'times')
{
$total = $_POST['number1'] *
$_POST['number2'];
}
if($_POST['operation'] == 'divided by')
{
$total = $_POST['number1'] /
$_POST['number2'];
}
if($_POST['operation'] == 'modulus')
{
$total = $_POST['number1'] %
$_POST['number2'];
}
}
else
{
echo"Numeric values are required";
}
}
?>

Prepared By: Chirag Parmar(IT1805) 17


Web Programming (PS02CINT24)

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


<table border=0 align="center">
<tr align="center">
<td><h1>CALCULATOR</td></h1>
</tr>
<tr>
<td>
<input name="number1" type="text" class="action-control" />
<select name="operation">
<option value="plus">+</option>
<option value="minus">-</option>
<option value="times">*</option>
<option value="divided by">/</option>
<option value="modulus">%</option>
</select>
<input name="number2" type="text" class="action-control" />
<input name="submit" type="submit" value="CALCULATOR" />
</td>
</tr>
<tr>
<td align="center"><input type="text" name="result" value="<?php echo
@$total ?>" disabled></td>
</tr>
</table>
</form>
</body>
</html>
OUTPUT:-

Q17 Write HTML and PHP script to check whether given number is
armstrong or not. Take the input through text box and display output
also in text box.
<html>
<body>
<form action="" method="post">
<input type="text" name="number">
<input type="submit">
</form>
</body>
</html>
<?php
if($_POST )
$number = $_POST['number'];
$t1 = $number;
$sum = 0;
while($t1 != 0)
{
$rem = $t1 % 10;
$sum = $sum + ( $rem * $rem * $rem);
$t1 = $t1 / 10;

Prepared By: Chirag Parmar(IT1805) 18


Web Programming (PS02CINT24)

}
if($number == $sum)
{
echo "$number is armstrong number";
}
else
{
echo "$number is not armstrong number";
}
?>
OUTPUT:-

Q18 Write HTML and PHP code to find factorial n numbers using recursion
function. (i.e. HTML allows to enter input through textbox and when
submit button is clicked then it displays numbers)
<html>
<head>
</head>
<body>
<form method="POST">
Enter number:-
<input type="number" name="number"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$number = $_POST['number'];
$fact = factorial($number);
echo"factorial of number:".$fact;
}
function factorial($number)
{
if($number<=1)
{
return 1;
}
else
{
return ($number * factorial($number-1));
}
}
?>
OUTPUT:-

Prepared By: Chirag Parmar(IT1805) 19


Web Programming (PS02CINT24)

Q19 Design Login form and validate to username=’admin’ and


Password=’admin123’. Display appropriate message.
<html>
<body>
<form action="#" method="post">
<table border=0 align="center" cellpadding=15 cellspacing=20>
<tr align="center">
<td colspan=2>LOGIN</td>
</tr>
<tr align="center">
<td class="font">LOGIN ID</td>
<td><input type="text" name="lid"></td>
</tr>
<tr align="center">
<td align="center">PASSWORD</td>
<td><input type="password" name="pwd"></td>
</tr>
<tr align="center">
<td><input type="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
if($_POST['lid'] == "admin" && $_POST['pwd'] == "admin")
{
echo "Login Successfull";
}
else
{
echo "Login Unsuccessfull";
}
}
?>
OUTPUT:-

Prepared By: Chirag Parmar(IT1805) 20


Web Programming (PS02CINT24)

Q20 Display current date in DD/MM/YYYY format


<?php
echo "Today is ...".date("d/m/y").
"<br>";
echo "Today is ...".date("d.m.y").
"<br>";
echo "Today is ...".date("d-m-y").
"<br>";
echo "Today is ...".date("l");
?>
OUTPUT:-

Q21 Write a program to show global , static and local variable.


<?php
$x = 3;
$y = 5;
function myTest()
{
static $a = 0;
$x =7;
echo "<br>"."Local Variable".$x."<br>"."Static Variable".$a;
$a++;
echo "<br>";
}
function accessglobal()
{
global $x, $y;
$r = $x + $y;
echo "Global variable sum=".$r."<br>";
}
echo "<br>"."Global variable sum".$x."<br>";
myTest();
myTest();
accessglobal();
?>
OUTPUT:-

Prepared By: Chirag Parmar(IT1805) 21


Web Programming (PS02CINT24)

Q22 Write a program to apply strlen(), strpos(), strrev(),strchr() & trim()


function.
<?php
$a='ISTAR IS COLLEGE';
$b='COLLEGE';
$c='IS';
echo'<br>'.'string length:'.strlen($a).'<br>';
echo'string position:'.strpos($a,$b).'<br>';
echo'string reverse:'. strrev($a).'<br>';
echo'strchr(ascii):'.strchr($a,65).'<br>';
echo'strchr(single character):'.strchr($a,'L').'<br>';
echo'strchr():'.strchr($a,'C').'<br>';
echo strchr("ISTAR COLLEGE","ISTAR",true);
echo strchr("shivani chauhan"," chauhan ",false).'<br>';
echo'strchr():'.strchr($a,'IS',FALSE).'<br>';
echo'trim():'.trim($a,'IE').'<br>';
var_dump($c);
?>
OUTPUT:-

Q23 Find the greater value between three variables using Ternary
Operator.
<html>
<body>
<form method="POST">
enter no1:<input type="text" name="n1"></br>
enter no2:<input type="text" name="n2"></br>
enter no3:<input type="text" name="n3"></br>
<input type="submit" name="submit" value="find!":>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$a=$_POST['n1'];

Prepared By: Chirag Parmar(IT1805) 22


Web Programming (PS02CINT24)

$b=$_POST['n2'];
$c=$_POST['n3'];
$greater = ($a>$b?($a>$c?$a:$c):($b>$c?$b:$c));
echo $greater." is greater value";
}
?>
OUTPUT:-

Q24 Write a PHP Script to:


a) Create a database my_db.
b) Create a table person.
c) Insert some data into table person.
d) Inserting some data into person through HTML form.
e) Select some data from person using different queries.
f) Update some record with SQL query.
g) Display all the tables in the database my_db.
h) Displaying all the databases.
1. Create a database my_db.
<?php
$con=mysqli_connect('localhost','root','');
if($con==true){
echo "Connected";
}
else
{
echo "Not connected";
}
$sql="CREATE DATABASE mydb";
$run=mysqli_query($con,$sql);
?>
Output:

2. Create a table person.


<?php
$con = mysqli_connect("localhost", "root", "", "mydb");
$sql = "CREATE TABLE persons(id INT NOT NULL PRIMARY
KEYAUTO_INCREMENT,
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL,
email VARCHAR(70) NOT NULL UNIQUE
)";
if(mysqli_query($con, $sql)){
echo "Table created successfully.";

Prepared By: Chirag Parmar(IT1805) 23


Web Programming (PS02CINT24)

} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($con);
}
mysqli_close($con);
?>
Output:

3. Insert some data into table person


<?php
$con = mysqli_connect("localhost", "root", "", "mydb");
$sql = "INSERT INTO persons (id,first_name,last_name,email)
VALUES ('1','John', 'Doe', '[email protected]')";
If(mysqli_query($con,$sql))
{
Echo “data inserted”:
}
else
{
Echo “error”:
}
?>
4. Inserting some data into person through HTML form.
<html>
<head>
</head>
<body>
<form method="POST"align="center">
<input type="text" name="id"></br>
<input type="text" placeholder="Enter your First name"
name="fname"></br>
<input type="text" placeholder="Enter your Last name" name
="lname"></br>
<input type="Email" placeholder="Enter your Email" name=
"email"></br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
$con=mysqli_connect('localhost','root','','mydb');
$id=$_POST['id'];
$first=$_POST['fname'];
$last=$_POST['lname'];
$email=$_POST['email'];
$sql="INSERT INTO `persons`(`id`, `first_name`, `last_name`,
`email`) VALUES ('$id','$first','$last','$email')";
$run=mysqli_query($con,$sql);
?>
5. Select some data from person using different queries

Prepared By: Chirag Parmar(IT1805) 24


Web Programming (PS02CINT24)

<pre>
<?php
$con = mysqli_connect("localhost", "root", "", "mydb");

$sql = "SELECT id, first_name, last_name, email FROM persons";


$run=mysqli_query($con,$sql);
$data=mysqli_fetch_array($run);
while($data=mysqli_fetch_array($run)) {
print_r($data);
}
?>
</pre><?php
$con = mysqli_connect("localhost", "root", "", "mydb");
$sql = "SELECT id, first_name, last_name, email FROM persons";
$run=mysqli_query($con,$sql);
$data=mysqli_fetch_array($run);
while($data=mysqli_fetch_array($run)) {
print_r($data);
}
?>
</pre>
Output:

6. Update some record with SQL query.


<?php
$con = mysqli_connect("localhost", "root", "", "mydb");
$sql="UPDATE persons SET last_name='Doe' WHERE id=2";
If(mysqli_query($con,$sql))
{
Echo “data updated”:
}
Else
{
Echo “error”:
}
?>
7. Display all the tables in the database my_db.
<?php
$con = mysqli_connect("localhost", "root", "", "mydb");
$sql="select * from tab";

Prepared By: Chirag Parmar(IT1805) 25


Web Programming (PS02CINT24)

$run=mysqli_query($con,$sql);
$data=mysqli_fetch_array($run);
while($data=mysqli_fetch_array($run)){
print_r($data);
}
?>
OUTPUT:-

Date:01/04/2019 Faculty Sign. :-

Prepared By: Chirag Parmar(IT1805) 26

You might also like