Web Programming 19IT02
Web Programming 19IT02
Output:
------------------------------------------------------------------------------------------------------------
Change the size of the image to 250 width and 400 height.
<html><head><title>p2</title></head>
< body><img src="istar.png" width="250pt" height="400pt"></body>
</html>
Output:
------------------------------------------------------------------------------------------------------------
Transform the text click here into a link that goes to
"https://www.google.com".
<html>
<head><title>p3</title></head>
<body><b><center><a href=https://www.google.com>Click Here</a>
</center></b></body>
Output:
-------------------------------------------------------------------------------------------------
The image no.2 does not exist. Specify the alternate text "istar.edu.in"
for the image.
<html><head><title>p4</title></head>
Output:
-------------------------------------------------------------------------------------------------
Image as a Link.
<html><head><tittle>p5</title></head>
<body><a href=”test.html”><img src=”istar.png” width=”250” height=”400”>
</a></body>
Output:
-------------------------------------------------------------------------------------------------
Add six headings to the document with the text "ISTAR”.
<html><head><title>p6</title></head>
<body><center><H1>ISTAR</H1><H2>ISTAR</H2><H3>ISTAR</H3><H4>ISTA
R</H4><H5>ISTAR</H5><H6>ISTAR</H6></center></body>
Output:
-------------------------------------------------------------------------------------------------
Change the text color of the paragraph to “red”
<html><head><title>p6</title></head>
<body><font color=red>
<p> M.Sc IT is a two year duration course.It helps student to develop skills required
Output:
-------------------------------------------------------------------------------------------------
Change the background color of the page.
<html><head><title>p7</title>
<body bgcolor=black>
<font color=white>
<p> M.Sc IT is a two year duration course.It helps student to develop skills required
to join computer industry.</p></font></body></head></html>
Output:
-------------------------------------------------------------------------------------------------
Use an HTML element to add quotation marks around the letters
"ISTAR".
<html><head><title>p8</title>
<p> M.Sc IT at <q>ISTAR</q> is a two year duration course.</p></head></html>
Output:
-------------------------------------------------------------------------------------------------
The letters "HTML" in the text below is an abbreviation of "Hyper Text
Markup Language".
<html><head><title>p9</title>
Output:
Output:
-------------------------------------------------------------------------------------------------
b) Different heading tags ( h1 to h6)
<H1>ISTAR</H1>
<H2>ISTAR</H2>
<H3>ISTAR</H3>
<H4>ISTAR</H4>
<H5>ISTAR</H5>
<H6>ISTAR</H6>
Output:
-------------------------------------------------------------------------------------------------
c) Paragraph
<p> M.Sc IT is a two year duration course.It helps student to develop skills required
to join computer industry.</p>
Output:
-------------------------------------------------------------------------------------------------
d) Horizontal line
<p>M.Sc IT is a two year duration course.It helps student to develop skills required
<hr> to join computer industry.</p>
Output:
-------------------------------------------------------------------------------------------------
e) Line Break
<p>M.Sc IT is a two year duration course.It helps student to develop skills required
<br> to join computer industry.</p>
Output:
----------------------------------------------------------------------------------------------------------
f) Block Quote
<p>About ISTAR College</p>
<blockquote cite="http://www.istar.edu.in/">M.Sc IT is a two year duration
course.It helps student to develop skills required to join computer
industry.</blockquote>
Output:
----------------------------------------------------------------------------------------------------------
g) Pre tag
<pre>
Bansari Patel
Female
22
</pre>
Output:
----------------------------------------------------------------------------------------------------------
h) Different Logical Style (<b>,<big>,<i>,<small>,<sub>,<sup>…)
<b>Bold</b><br>
<big>Big</big><br>
<i>Italic</i><br>
<small>Small</small><br>
<font>This is example of<sub>Sub</sub><br>
This is example of<sup>Sup</sup></font>
Output:
----------------------------------------------------------------------------------------------------------
i)Different Physical Style
(<cite><code>,<del>,<dfn>,<em>,<ins><samp>,<strong>…)
<p> This is an example of -><cite>cite tag</cite>.<br/>
Code tag is used to highlight code used in computer like -> <code> sqrt()
</code><- function.<br/>
This is an example of -><del>del tag</del>.<br/>
-><dfn>dfn tag</dfn><- is used to mark the term whose defination is
provided in line.<br/>
This is an example of -><em>em tag</em>.<br/>
Ins tag is used to insert new data.i.e using ins tag "This is an example of" can
be changed into "This is an example of -><ins>ins tag.</ins><-<br/>
samp tag is used to highlight output of a computer like this -> <samp> Output
</samp><-.<br/>
Output:
----------------------------------------------------------------------------------------------------------
j)Listing Tags
<body>
<ul>
<li> PG
<ol>
<li>Science
<ul type="circle">
<li>MCA</li>
<li>M.Sc.IT</li>
<li>M.Sc.Science</li>
</ul>
</li>
<li>Commerce
<ul type="dot">
<li>MBA</li>
<li>M.Com.</li>
</ul>
</li>
</ol>
</li>
<li> UG
<ol type="i">
<li> Science
<ol type="a" start="b">
<li>BCA</li>
<li>B.Sc.IT</li>
</ol>
</li>
<li> Commerce
<ol type="1" start="4">
<li>B.Com.</li>
<li>BBA</li>
</ol>
</li>
</ol>
</li>
</ul>
</body>
Output:
Output:
<tr>
<th colspan = 3>Subtotal</th>
<td>50</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan = 2>Seminar</th>
<td>01</td>
<td>01</td>
</tr>
<tr>
<th colspan = 3>Grand Total</th>
<td>51</td>
</tr>
</tfoot>
</table>
Output:
Output:
}
else if(e == "")
{
alert("Please Enter Your Age");
document.form1.age.focus();
return false;
}
else if(isNaN(e) || (e < 0) || (e > 100))
{
alert("Please Enter age between 0 and 100");
document.form1.age.value = "";
document.form1.age.focus();
return false;
}
else if(document.form1.address.value == "")
{
alert("Please Enter Your Address");
document.form1.address.focus();
return false;
}
var c = document.form1.gender;
var d = document.form1.language;
var i = 0;
var radioresult = false;
var checkboxresult = false;
}
document.form1.submit.disabled = false;
return true;
}
</script>
</head>
<body>
<form name = "form1" action = "https://www.google.com" method = "post">
<font color = "red">
<table style = "background-color:lightskyblue; border-spacing: 10px">
<tr>
<th colspan="2">ENTRY FORM</th>
</tr>
<tr>
<th align="left" valign="top">Enter your Name: </th>
<td>
<input type="text" id="name1" name="name">
</td>
</tr>
<tr>
<th align="left" valign="top">Enter your Age: </th>
<td>
<input type="text" name="age">
</td>
</tr>
<tr>
<th align="left" valign="top">Enter your Address:</th>
<td>
<textarea name = "address" rows="3" cols="50"></textarea>
</td>
</tr>
<tr>
<th align="left" valign="top">gender:</th>
<td>
<input type="radio" name="gender" id="rd1" value="female">
Female <br>
<input type="radio" name="gender" id="rd2" value="male">Male
<br>
<input type="radio" name="gender" id="rd3" value="other">Other
</td>
</tr>
<tr>
<th align="left" valign="top">Languages:
</th>
<td>
<input type="checkbox" name="language" value="html">HTML<br>
<input type="checkbox" name="language"
value="php">PHP<br>
<input type="checkbox" name="language" value="asp">ASP<br>
<input type="checkbox" name="language" value="others">OTHERS
</td>
</tr>
<tr>
Output:
#btn1,#btn2{
background-color: green;
padding:5px;
width:200px;
transition:1s;
}
#btn1:hover,#btn2:hover{
background-color: blue;
padding:8px;
width:240px;
cursor:pointer;
color:white;
}
<!DOCTYPE html>
<html>
<head>
<title>Reg Form</title>
<link rel="stylesheet" type="text/css" href="program7css.css">
<script type="text/javascript">
function validate(){
var F_name = document.forms["myForm"]["FName"];
var L_name = document.forms["myForm"]["LName"];
var B_day = document.forms["myForm"]["Bday"];
var Add = document.forms["myForm"]["Address"];
var S_City = document.forms["myForm"]["City"];
var S_State = document.forms["myForm"]["State"];
var S_Country = document.forms["myForm"]["Country"];
var Pin = document.forms["myForm"]["Pincode"];
var R_Gender=document.getElementsByName('Gender');
var R_Course=document.getElementsByName('Course');
var C_Box=document.forms["myForm"]["H"];
var Ch_Result=false;
var Ch_Other = document.forms["myForm"]["Other"];
var Ch_Other_Text = document.forms["myForm"]["OtherText"];
var B1=document.forms["myForm"]["Bord1"];
var B2=document.forms["myForm"]["Bord2"];
var B3=document.forms["myForm"]["Bord3"];
var B4=document.forms["myForm"]["Bord4"];
var P1=document.forms["myForm"]["Percentage1"];
var P2=document.forms["myForm"]["Percentage2"];
var P3=document.forms["myForm"]["Percentage3"];
var P4=document.forms["myForm"]["Percentage4"];
var Pass1=document.forms["myForm"]["Passing1"];
var Pass2=document.forms["myForm"]["Passing2"];
var Pass3=document.forms["myForm"]["Passing3"];
var Pass4=document.forms["myForm"]["Passing4"];
if (F_name.value == ""){
window.alert("Please enter your First name.");
F_name.focus();
return false;
}
if (L_name.value == ""){
alert("value Nakh");
return false;
}
if(C_Box[3].checked){
if(Ch_Other_Text.value==""){
alert("Other nakh");
return false;
}
}
if(B1.value==""){
window.alert("Please Enter your Bord name.");
B1.focus();
return false;
}
if(B2.value==""){
window.alert("Please Enter your Bord name.");
B2.focus();
return false;
}
if(B3.value==""){
window.alert("Please Enter your Bord name.");
B3.focus();
return false;
}
if(B4.value==""){
window.alert("Please Enter your Bord name.");
B4.focus();
return false;
}
if(P1.value=="" || isNaN(P1.value)){
window.alert("Please Enter your Per % .");
P1.focus();
return false;
}
if(P1.value<0 || P1.value>100){
alert("Please ENter Value Between 0 to 100");
P1.focus();
return false;
}
if(P2.value=="" || isNaN(P2.value)){
window.alert("Please Enter your Per % .");
P2.focus();
return false;
}
if(P2.value<0 || P2.value>100){
alert("Please ENter Value Between 0 to 100");
P2.focus();
return false;
}
if(P3.value=="" || isNaN(P3.value)){
window.alert("Please Enter your Per % .");
P3.focus();
return false;
}
if(P3.value<0 || P3.value>100){
alert("Please ENter Value Between 0 to 100");
P3.focus();
return false;
}
if(P4.value=="" || isNaN(P4.value)){
window.alert("Please Enter your Per % .");
P4.focus();
return false;
}
if(P4.value<0 || P4.value>100){
alert("Please ENter Value Between 0 to 100");
P4.focus();
return false;
}
if(isNaN(Pass1.value) || Pass1.value.length !=4){
alert("Enter Appropriate numbver");
Pass1.focus();
return false;
}
if(isNaN(Pass2.value) || Pass2.value.length !=4){
alert("Enter Appropriate numbver");
Pass1.focus();
return false;
}
if(isNaN(Pass3.value) || Pass3.value.length !=4){
alert("Enter Appropriate numbver");
Pass1.focus();
return false;
}
if(isNaN(Pass4.value) || Pass4.value.length !=4){
alert("Enter Appropriate numbver");
Pass1.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form method="POST" action="program7.html" id="myForm" onsubmit="return
validate () ">
<table border="1" > <!-- background="istar.jpg"-->
<tr>
<td colspan="2"><center><img src="logo.png"></center></td>
</tr>
<tr>
<td colspan="2"><center><p>MSc.IT Department</p></center></td>
</tr>
<tr>
<td colspan="2"><center><p>Student Registration Form </p> </center>
</td>
</tr>
<tr>
<th>First Name</th>
<tr>
<th>Birth Date</th>
<td><input type="date" name="Bday" max="2019-12-31"></td>
</tr>
<tr>
<th>Address</th>
<td>
<textarea rows="5" cols="60" name="Address" placeholder="Enter
Address Here...."></textarea>
</td>
</tr>
<tr>
<th>City</th>
<td>
<select type="text" value="" name="City">
<option value = "-1" selected>[choose city]</option>
<option>Surat</option>
<option>Bharuch</option>
<option>Ankleshwar</option>
</select>
</td>
</tr>
<tr>
<th>State</th>
<td>
<select type="text" value="" name="State">
<option value = "-1" selected>[choose state]</option>
<option>Gujrat</option>
<option>UP</option>
<option>MP</option>
</select>
</td>
</tr>
<tr>
<th>Country</th>
<td>
<select type="text" value="" name="Country">
<option value = "-1" selected>[choose country]</option>
<option>India</option>
<option>U.K</option>
<option>U.A.E</option>
</select>
</td>
</tr>
<tr>
<th>Gender</th>
<td>
<input type="radio" name="Gender" value="male"> Male
<input type="radio" name="Gender" value="female"> Female
</td>
</tr>
<tr>
<th>Course</th>
<td>
B.Sc<input type="radio" name="Course" value="B.Sc">
M.Sc<input type="radio" name="Course" value="M.Sc">
BCA<input type="radio" name="Course" value="BCA">
MCA<input type="radio" name="Course" value="MCA">
</td>
</tr>
<tr>
<th>Pincode</th>
<td><input type="text" placeholder="Enter Pincode" pattern="^[0-9]{6}$"
title="Enter Valid Pin Code(max 6 number)" name="Pincode"></td>
</tr>
<tr>
<th>Hobbies</th>
<td>
Singing<input type="checkbox" name="H" value="Singing">
Playing<input type="checkbox" name="H" value="Playing">
Dancing<input type="checkbox" name="H" value="Dancing">
Other<input type="checkbox" name="H" value="Dancing">
<input type="text" name="OtherText">
</td>
</tr>
<tr>
<th>Qualification</th>
<td><!-- This cell contains a table: -->
<table border="1">
<tr>
<th>SR.No</th>
<th>Examination</th>
<th>Board</th>
<th>Percentage</th>
<th>Year of Passing</th>
</tr>
<tr>
<th>1</th>
<th>Class X</th>
<td><input type="text" name="Bord1"></td>
<td><input type="text" name="Percentage1"></td>
<td><input type="text" name="Passing1"></td>
</tr>
<tr>
<th>2</th>
<th>Class XII</th>
<td><input type="text" name="Bord2"></td>
<td><input type="text" name="Percentage2"></td>
<td><input type="text" name="Passing2"></td>
</tr>
<tr>
<th>3</th>
<th>Graduation</th>
<td><input type="text" name="Bord3"></td>
<td><input type="text" name="Percentage3"></td>
<td><input type="text" name="Passing3"></td>
</tr>
<tr>
<th>4</th>
<th>Master</th>
<td><input type="text" name="Bord4"></td>
<td><input type="text" name="Percentage4"></td>
<td><input type="text" name="Passing4"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td></td>
<td>
<center id="btn">
<input type="submit" value="submit Data" name="Submit" id="btn1">
<button type="reset" value="Reset" id="btn2">Reset</button>
</center>
</td>
</tr>
</table>
</form>
</body>
</html>
Output:
8. Show the use of events to change background color with HTML and
JavaScript.
1.If mouse button is pressed, background color should be red.
2.If mouse button is released up, background color should be yellow.
Solution: <head>
<script type= "text/javascript">
function myBlurFunction()
{
document.body.style.background = "red";
}
function myClickFunction()
{
document.body.style.background = "yellow";
}
</script>
</head>
<body>
<input type = "button" value= "Color" onmouseup="myBlurFunction()"
onmousedown ="myClickFunction()">
</body>
Output:
Output:
10. Write a program to show use of alert, confirm and prompt box.
Solution: <html>
<head>
<title> Program 10 </title>
<script type="text/javascript">
function myAlert()
{
alert("This is an alert box");
}
function myPrompt()
{
prompt("This is an example of prompt box");
}
function myConfirm()
{
confirm("This is an example of confirm box");
}
</script>
</head>
<body>
<input type="button" value="Alert" name="alert" onclick="myAlert()">
<input type="button" value="Confirm" name="Confirm" onclick="myConfirm()"
>
<input type="button" value="Prompt" name="prompt" onclick="myPrompt()">
</body>
</html>
Output:
{
c = i * i;
b += (i + " ^ 2 = " + c + "\n");
}
alert(b);
}
</script>
</head>
<body>
<input type = "button" value = "Print squares" onclick =" mySquareFunction()"/>
</body>
Output:
Output:
Output:
Output:
Output:
$z = $x + $y;
return $z;
}
$x = add(2, 3);
echo "The addition of 2 + 3= $x<br/>";
echo "The addition of 4 + 6= ".add(4, 6)."<br/>";
echo "The addition of 6 + 9= ".add(6, 9)."<br/>";
?>
Output:
break;
case "/":
$result = $num1 / $num2;
break;
case "%":
$result = $num1 % $num2;
break;
case "**":
$result = $num1 ** $num2;
break;
default:
$error3 = "Invalid Operation";
break;
}
}
}
if(isset($_POST['clear']))
{
$num1 = $num2 = $opr = $result = NULL;
}
?>
<html>
<head>
<title>Program 17</title>
<style>
.error{color:red;}
</style>
</head>
<body>
<form method="post">
<table border="2" style="margin-left:auto;margin-right:auto;">
<tr>
<th align="left">Enter First Number:</th>
<td>
<input type="text" name="num1" value="<?php echo $num1; ?>"/>
<br/>
<span class="error"><?php echo $error1;?></span>
</td>
</tr>
<tr>
<th align="left">Enter Operator:</th>
<td>
<input type="text" name="operator" placeholder="values from(+,-,/,*,
%,**)" value="<?php echo $opr;?>"/><br/>
<span class="error"><?php echo $error3; ?></span>
</td>
</tr>
<tr>
<th align="left">Enter Second Number:</th>
<td>
<input type="text" name="num2" value="<?php echo $num2; ?>"/>
<br/>
<span class="error"><?php echo $error2;?></span>
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" name="submit" value="Submit"/>
<input type="submit" name="clear" value="Clear"/>
</td>
</tr>
<tr>
<th align="left">Result:</th>
<td>
<input type="text" name="result" value="<?php echo $result;?>"/>
<br/>
</td>
</tr>
</table>
</form>
</body>
</html>
Output:
18. Display your name n times. Take the input through text box.
Solution: <?php
$hide = NULL;
if(isset($_POST['submit']))
{
$a = $_POST["name"];
$b = $_POST["repeater"];
$hide = "hidden";
for($i = 1; $i <= $b; $i++)
{
echo "$a<br/>";
}
}
?>
<html>
<form method="post" <?php echo $hide;?>>
<table border="2" style="margin-left:auto;margin-right:auto;">
<tr>
<th>Enter Name:</th>
<td><input type="text" name="name"></td>
</tr>
<tr>
<th>Repeat for:</th>
Output:
19. Write HTML and PHP script to check whether given number is odd or
even. Take the input through text box.
Solution: <?php
$error = NULL;
$number = NULL;
$result = NULL;
if(isset($_POST['number']))
{
$number = $_POST['num1'];
if(!(is_numeric($number)))
{
$error = "Please Enter a number";
}
else
{
if($number % 2 == 0)
$result = "$number is an even number.";
else
$result = "$number is an odd number.";
}
}
if(isset($_POST['clear']))
{
$number = $error = $result = NULL;
}
?>
<html>
<head>
<title>Program 19</title>
<style>
.error{color:red;}
</style>
</head>
<body>
<form name="form1" method="post">
Output:
}
function reset()
{
document.getElementById("screen").value = '';
}
-->
</script>
</head>
<body>
<form name="myform">
<table border=2 style="margin-left:auto;margin-right:auto;">
<tr>
<td align="center">
<input type="text" id="screen" name="screen" style="width:99%">
<br>
</td>
</tr>
<tr>
<td>
<input type="button" name="7" value=" 7 " onclick="update(7)">
<input type="button" name="8" value=" 8 " onclick="update(8)">
<input type="button" name="9" value=" 9 " onclick="update(9)">
<input type="button" name="+" value=" + " onclick="update('+')">
<br>
<input type="button" name="4" value=" 4 " onclick="update(4)">
<input type="button" name="5" value=" 5 " onclick="update(5)">
<input type="button" name="6" value=" 6 " onclick="update(6)">
<input type="button" name="-" value=" - " onclick="update('-')">
<br>
<input type="button" name="1" value=" 1 " onclick="update(1)">
<input type="button" name="2" value=" 2 " onclick="update(2)">
<input type="button" name="3" value=" 3 " onclick="update(3)">
<input type="button" name="*" value=" x " onclick="update('*')">
<br>
<input type="button" name="c" value=" c " onclick="reset();">
<input type="button" name="0" value=" 0 " onclick="update(0)">
<input type="button" name="=" value=" = " onclick="result();">
<input type="button" name="/" value=" / " onclick="update('/')">
</td>
</tr>
</table>
</form>
</body>
</html>
Output:
21. 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.
Solution: <?php
$error = NULL;
$number = NULL;
$result = NULL;
if(isset($_POST['number']))
{
$number = $_POST['num1'];
if(!(is_numeric($number)))
{
$error = "Please Enter a number";
}
else if(is_int($number))
{
$error = "Please Enter Integer Number";
}
else
{
$temp = $number;
$sum = 0;
while($temp != 0)
{
$r = $temp % 10;
$temp /= 10;
$sum += ($r ** 3);
}
if($number == $sum)
$result = "$number is an armstrong number.";
else
$result = "$number is not an armstrong number.";
}
}
if(isset($_POST['clear']))
{
$number = $error = $result = NULL;
}
?>
<html>
<head>
<title>Program 19</title>
<style>
.error{color:red;}
</style>
</head>
<body>
<form name="form1" method="post">
<table border="2" style="margin-left:auto;margin-right:auto;">
<tr>
<th>Enter Number:</th>
<td>
<input type="text" name="num1" size=25 value="<?php echo $number
;?>"><br/><span class="error"><?php echo $error;?></span>
</td>
</tr>
<tr>
<td colspan="2" align="center">
Output:
22. 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)
Solution: <?php
$number = NULL;
$error = NULL;
$result = NULL;
function fact($number)
{
if($number == 1)
{
return 1;
}
else
{
return $number * fact($number - 1);
}
}
if(isset($_POST['number']))
{
$number = $_POST['num1'];
if(!(is_numeric($number)))
{
$error = "Please Enter a number";
}
else if(is_int($number))
{
$error = "Please Enter Integer Number";
}
else
{
$result = fact($number);
}
}
if(isset($_POST['clear']))
{
$number = $error = $result = NULL;
}
?>
<html>
<head>
<title>Program 22</title>
<style>
.error{color:red;}
</style>
</head>
<body>
<form name="form1" method="post">
<table border="2" style="margin-left:auto;margin-right:auto;">
<tr>
<th>Enter Number:</th>
<td>
<input type="text" name="num1" size=25 value="<?php echo
$number;?>"><br/><span class="error"><?php echo $error;?></span>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="number" value="Find Factorial"/>
<input type="submit" name="clear" value="Clear"/>
</td>
</tr>
<tr>
<th>Result:</th>
<td>
<input type="text" name="result" size=25 value="<?php echo $result;?>
"/>
</td>
</tr>
</table>
</form>
</body>
</html>
Output:
Output:
Output:
$a = 50;
static $b = 70;
function localise()
{
$a = 60;
return $a;
}
echo "Global Variable is $a<br/>";
echo "Static Variable is $b<br/>";
echo "Local Variable is ".localise();
?>
Output:
26. Write a program to apply strlen(), strops(), strrev(), strchr() & trim()
function.
Solution: <?php
$a = "ISTAR is a college";
$b = "college";
$c = "is";
echo "First string is: $a <br/>";
echo "Second string is: $b <br/>";
echo "Third string is: $c <br/>";
echo "Lenght of string First is: ".strlen($a)."<br/>";
echo "The position of string Second in First String is: ".strpos($a, $b)."<br/>";
echo "The position of string Third in First String is: ".strpos($a, $c)."<br/>";
echo "The words before string Third in First String is: ".strchr($a, $c,TRUE);
echo “<br/>";
echo "The words after string Third in First String is: ".strchr($a, $c,FALSE);
echo "<br/>";
echo "The string after triming string First by 'ISge' is: ".trim($a, 'ISge')."<br/>";
define('Constant1', "This is a constant", TRUE)."<br/>";
echo Constant1;
?>
Output:
27. Find the greater value between three variables using Ternary Operator.
Solution: <?php
$a = 5;
$b = 7;
$c = 3;
echo "Maximum Number is: ".(($a >= $b && $a >= $c)? $a : (($b >= $c)? $b : $c));
?>
Output:
if(mysqli_query($conn, $sql))
{
echo "Database Created Successfully.<br/>";
}
else
{
echo "Database creation failed.".mysqli_error($conn);
}
?>
Output:
$user = "root";
$pwd = "";
$database = "my_db";
$conn = mysqli_connect($server, $user, $pwd, $database);
if(!($conn))
{
die("Connection Failed".mysqli_connect_error());
}
$sql = "create table person"
. "(personid int(5) unsigned auto_increment primary key,"
. "firstname varchar(30) not null,"
. "lastname varchar(30) not null,"
. "address varchar(60) not null,"
. "city varchar(30) not null)";
if(mysqli_query($conn, $sql))
{
echo "table created successfully.<br/>";
}
else
{
die("Table creation failed.".mysqli_error($conn));
}
mysqli_close($conn);
?>
Output:
Output:
$read = "readonly";
$result ="Record insert Successfull";
}
else
{
$class = "error";
$result = "Record insert failed".mysqli_error($conn);
}
mysqli_close($conn);
}
}
if(isset($_POST['clear']))
{
$f_name = $l_name = $address = $city = $read = NULL;
$f_err = $l_err = $add_err = $city_err = $result = NULL;
$flag = TRUE;
}
?>
<html>
<head>
<title>P28</title>
<style>
.error{color:red;}
.success{color:green;}
</style>
</head>
<body>
<form method="post">
<table border="2" style="margin-left:auto; margin-right:auto;">
<tr>
<th>First Name:</th>
<td>
<input type="text" name="f_name" value="<?php echo $f_name;?>"
<?php echo $read;?>/><br/>
<span class="error"><?php echo $f_err;?></span>
</td>
</tr>
<tr>
<th>Last Name:</th>
<td>
<input type="text" name="l_name" value="<?php echo $l_name;?>"
<?php echo $read;?>/><br/>
<span class="error"><?php echo $l_err;?></span>
</td>
</tr>
<tr>
<th>Address:</th>
<td>
<input type="text" name="address" value="<?php echo $address;?>"
<?php echo $read;?>/><br/>
<span class="error"><?php echo $add_err;?></span>
</td>
</tr>
<tr>
<th>City:</th>
<td>
<input type="text" name="city" value="<?php echo $city;?>" <?php
echo $read;?>/><br/>
<span class="error"><?php echo $city_err;?></span>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="insert" value="Insert">
<input type="submit" name="clear" value="Clear"/><br/>
</td>
</tr>
</table>
<div style="text-align:center">
<span class="<?php echo $class;?>"><?php echo $result;?></span>
</div>
</form>
</body>
</html>
Output:
Output:
$pwd = "";
$database = "my_db";
$conn = mysqli_connect($server, $user, $pwd, $database);
if(!($conn))
{
die("Connection Failed".mysqli_connect_error());
}
$sql = "update person set address = 'AV Road', city = 'Anand' where"
. " firstname = 'Bansari'";
if(mysqli_query($conn, $sql))
echo "Data update is successful";
else
echo "Data updation is failed";
?>
Output: