Friday, March 17, 2017

add edit display in php

Add update and display

Config.php

<?php
$databaseHost = 'localhost';
$databaseName = 'test';
$databaseUsername = 'root';
$databasePassword = 'root';
 
$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName); 
?>

ADD.HTML
<html>
<head>
    <title>Add Data</title>
</head>

<body>
    <a href="index.php">Home</a>
    <br/><br/>

    <form action="add.php" method="post" name="form1">
        <table width="25%" border="0">
            <tr>
                <td>Name</td>
                <td><input type="text" name="name"></td>
            </tr>
            <tr>
                <td>Age</td>
                <td><input type="text" name="age"></td>
            </tr>
            <tr>
                <td>Email</td>
                <td><input type="text" name="email"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" name="Submit" value="Add"></td>
            </tr>
        </table>
    </form>
</body>
</html>

Add.php


<html>
<head>
    <title>Add Data</title>
</head>

<body>
<?php
//including the database connection file
include_once("config.php");

if(isset($_POST['Submit'])) {  
    $name = $_POST['name'];
    $age = $_POST['age'];
    $email = $_POST['email'];
       
    // checking empty fields
    if(empty($name) || empty($age) || empty($email)) {              
        if(empty($name)) {
            echo "<font color='red'>Name field is empty.</font><br/>";
        }
       
        if(empty($age)) {
            echo "<font color='red'>Age field is empty.</font><br/>";
        }
       
        if(empty($email)) {
            echo "<font color='red'>Email field is empty.</font><br/>";
        }
       
        //link to the previous page
        echo "<br/><a href='javascript:self.history.back();'>Go Back</a>";
    } else {
        // if all the fields are filled (not empty)            
        //insert data to database
        $result = mysqli_query($mysqli, "INSERT INTO users(name,age,email) VALUES('$name','$age','$email')");
       
        //display success message
        echo "<font color='green'>Data added successfully.";
        echo "<br/><a href='index.php'>View Result</a>";
    }
}
?>
</body>
</html>


EDIT.php


<?php
// including the database connection file
include_once("config.php");

if(isset($_POST['update']))
{  
    $id = $_POST['id'];
   
    $name=$_POST['name'];
    $age=$_POST['age'];
    $email=$_POST['email'];  
   
    // checking empty fields
    if(empty($name) || empty($age) || empty($email)) {          
        if(empty($name)) {
            echo "<font color='red'>Name field is empty.</font><br/>";
        }
       
        if(empty($age)) {
            echo "<font color='red'>Age field is empty.</font><br/>";
        }
       
        if(empty($email)) {
            echo "<font color='red'>Email field is empty.</font><br/>";
        }      
    } else {  
        //updating the table
        $result = mysqli_query($mysqli, "UPDATE users SET name='$name',age='$age',email='$email' WHERE id=$id");
       
        //redirectig to the display page. In our case, it is index.php
        header("Location: index.php");
    }
}
?>


<?php
//getting id from url
$id = $_GET['id'];

//selecting data associated with this particular id
$result = mysqli_query($mysqli, "SELECT * FROM users WHERE id=$id");

while($res = mysqli_fetch_array($result))
{
    $name = $res['name'];
    $age = $res['age'];
    $email = $res['email'];
}
?>
<html>
<head>  
    <title>Edit Data</title>
</head>

<body>
    <a href="index.php">Home</a>
    <br/><br/>
   
    <form name="form1" method="post" action="edit.php">
        <table border="0">
            <tr>
                <td>Name</td>
                <td><input type="text" name="name" value="<?php echo $name;?>"></td>
            </tr>
            <tr>
                <td>Age</td>
                <td><input type="text" name="age" value="<?php echo $age;?>"></td>
            </tr>
            <tr>
                <td>Email</td>
                <td><input type="text" name="email" value="<?php echo $email;?>"></td>
            </tr>
            <tr>
                <td><input type="hidden" name="id" value=<?php echo $_GET['id'];?>></td>
                <td><input type="submit" name="update" value="Update"></td>
            </tr>
        </table>
    </form>
</body>
</html>


INDEX.PHP


<?php
//including the database connection file
include_once("config.php");

//fetching data in descending order (lastest entry first)
//$result = mysql_query("SELECT * FROM users ORDER BY id DESC"); // mysql_query is deprecated
$result = mysqli_query($mysqli, "SELECT * FROM users ORDER BY id DESC"); // using mysqli_query instead
?>

<html>
<head>    
    <title>Homepage</title>
</head>

<body>
    <a href="add.html">Add New Data</a><br/><br/>

    <table width='80%' border=0>
        <tr bgcolor='#CCCCCC'>
            <td>Name</td>
            <td>Age</td>
            <td>Email</td>
            <td>Update</td>
        </tr>
        <?php 
        //while($res = mysql_fetch_array($result)) { // mysql_fetch_array is deprecated, we need to use mysqli_fetch_array 
        while($res = mysqli_fetch_array($result)) {         
            echo "<tr>";
            echo "<td>".$res['name']."</td>";
            echo "<td>".$res['age']."</td>";
            echo "<td>".$res['email']."</td>";    
            echo "<td><a href=\"edit.php?id=$res[id]\">Edit</a></td></tr>";        
        }
        ?>
    </table>
</body>

</html>

Friday, December 30, 2016

Series

Write a program print series.
1. 1 3 6 10 15
2. 2 4 7 11  16



void main()
{
int i,j=1;//same java,c,c++
for(int i=1;i<=5;i++)
{
j=j+i;
printf("%d",j);//c program
System.out.println(j);//java
cout<<j;//c++
}


}
2.
void main()
{
int i,j=0;//same java,c,c++
for(int i=1;i<=5;i++)
{
j=j+i;
printf("%d",j);//c program
System.out.println(j);//java
cout<<j;//c++
}


}

Wednesday, December 28, 2016

what is the difference between div and span tags


DIV TAG:

Following are the characteristics:
  1. As the name indicates, the div tag defines a ‘division’ in a web page.
  2. div is a block-element; its default display value is “block”.
  3. div tag is commonly used while creating Css based layouts in html.
  4. by default, a line-break is placed before and after this element.

SPAN TAG:

Following are the characteristics:
  1. span tag makes no visual difference in the page, unless customised with style attribute.
  2. span is an in-line element.
  3. span is commonly used to stylize texts. The in-line feature makes it easy to use custom styles without changing the layout.
  4. No line-breaks by default, but this can be achieved if we change its in-line nature by specifying in the style attribute to ‘display:block;’

Scalable Vector Graphics.

SVG stands for Scalable Vector Graphics.
SVG defines vector-based graphics in XML format.






<!DOCTYPE html>
<html>
<body>

<h1>My first SVG</h1>

<svg width="100" height="100">
   <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
   Sorry, your browser does not support inline SVG.
</svg> 

</body>
</html>




<!DOCTYPE html>
<html>
<body>

<svg width="400" height="110">
  <rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)">
  Sorry, your browser does not support inline SVG.
</svg>

</body>
</html>


Why use SVG at all?

  • Small file sizes that compress well
  • Scales to any size without losing clarity (except very tiny)
  • Looks great on retina displays
  • Design control like interactivity and filters

<!DOCTYPE html>
<html>
<body>

<svg width="400" height="180">
  <rect x="50" y="20" rx="20" ry="20" width="150" height="150" style="fill:red;stroke:black;stroke-width:5;opacity:0.5">
  Sorry, your browser does not support inline SVG.
</svg>

</body>
</html>


1) What is HTML?

HTML stands for Hyper Text Markup Language. It is a language of World Wide Web. It is a standard text formatting language which is used to create and display pages on the Web. 

2) What are Tags?

HTML tags are composed of three things: opening tag, content and ending tag. Some tags are unclosed tags.
HTML documents are made of two things:
  • content, and
  • tags
Content is placed between tags to display data on the web page.

3) Do all HTML tags have end tag?

No. There are some HTML tags that don't need a closing tag. For example: <image> tag, <br> tag. 

4) What are some common lists that are used when designing a page?

There are many common lists which are used to design a page. You can choose any or a combination of the following list types:
  • Ordered list
  • Unordered list
  • Menu list
  • Directory list
  • Definition list

6) What is semantic HTML?

Semantic HTML is a coding style. It is the use of HTML markup to reinforce the semantics or meaning of the content. For example: In semantic HTML <b> </b> tag is not used for bold statement as well as <i> </i> tag is used for italic. Instead of these we use <strong></strong> and <em></em> tags.

7) What is image map?

Image map facilitates you link many different web pages using a single image. You can define shapes in images that you want to make part of an image mapping.

8) How to insert a copyright symbol on a browser page?

can insert a copyright symbol by using &copy; or &#169; in an HTML file.

9) How do you keep list elements straight in an HTML file?

You can keep the list elements straight by using indents.

10) Does a hyperlink only apply to text?

No, you can use hyperlinks on text and images both. 

11) What is a style sheet?

A style sheet is used to build a consistent, transportable, and well designed style template. You can add these templates on several different web pages.

12) Can you create a multi colored text on a web page?

Yes. To create a multicolor text on a web page you can use <font color ="color"> </font> for the specific texts you want to color.

13) Is it possible to change the color of the bullet?

The color of the bullet is always the color of the first text of the list. So, if you want to change the color of the bullet, you must change the color of the text.

14) What is a marquee?

Marquee is used to put the scrolling text on a web page. You should put the text which you want to scroll within the <marquee>......</marquee> tag.


15) How many tags can be used to separate section of texts?

There are three tags used to separate the texts. i.e. usually <br> tag is used to separate line of texts. Other tags are<p> tag and <blockquote> tag.

16) How to make a picture a background image of a web page?

To make a picture a background image on a web page, you should put the following tag code after the </head> tag.
  1. <body background = "image.gif">  
Here, replace the "image.gif" with the name of your image file which you want to display on your web page.

17) What are empty elements?

HTML elements with no content are called empty elements. For example: <br>, <hr> etc.

18) What is the use of span tag? Give one example.

The span tag is used for following things:
  • For adding color on text
  • For adding background on text
  • Highlight any color text etc.
Example:
  1. <p>  
  2. <span style="color:#ffffff;">  
  3. In this page we use span.  
  4. </span>  
  5. </p>  

19) What is the use of iframe tag?

An iframe is used to display a web page within a web page.
Syntax:
  1. <iframe src="URL"></iframe>  
Example:
  1. <iframe src="demo_iframe.html" width="200px" height="200px"></iframe>  
Target to a link:
  1. <iframe src="http://www.javatpoint.com" name="iframe_a"></iframe>  

HTML5 Interview Questions

Let's see a list of top HTML5 interview questions and answers.

20) What is canvas in HTML5?

Canvas is an HTML area which is used to draw graphics. More details...

21) What is SVG?

HTML SVG is used to describe the two dimensional vector and vector/raster graphics. More details...

22) What are the different new form element types in HTML 5?

Following is a list of 10 important new elements in HTML 5:
  • Color
  • Date
  • Datetime-local
  • Email
  • Time
  • Url
  • Range
  • Telephone
  • Number
  • Search

23) Is there any need to change the web browsers to support HTML5?

No. Almost all browsers (updated versions) support HTML 5. For example: Chrome, Firefox, Opera, Safari, IE etc.

24) Which video formats are supported by HTML5?

HTML 5 supports three types of video format:
  • mp4
  • webm
  • ogg

25) Is audio tag supported in HTML 5?

Yes. It is used to add sound or music files on the web page. 

26) What is the difference between progress and meter tag?

The progress tag is used to represent the progress of the task only while the meter tag is used to measure data within a given range.

27) What is the use of figure tag in HTML 5?

The figure tag is used to add a photo in the document on the web page. More details...

28) What is button tag?

The button tag is used in HTML 5. It is used to create a clickable button within HTML form on the web page. It is generally used to create a "submit" or "reset" button. More details...

29) What does details and summary tag?

The details tag is used to specify some additional details on the web page. It can be viewed or hidden on demand. The summary tag is used with details tag. More details...

30) What is datalist tag?

The HTML 5 datalist tag provides an auto complete feature on form element. It facilitates users to choose the predefined options.

31) How tags are migrated from HTML4 to HTML5?

No.Typical HTML4Typical HTML5
1)<div id="header"><header>
2)<div id="menu"><nav>
3)<div id="content"><section>
4)<div id="post"><article>
5)<div id="footer"><footer>

Header and Footer Example

HTML 4 Header and Footer:
  1. <div id="header">  
  2.   <h1>Monday Times</h1>  
  3. </div>  
  4. .  
  5. .  
  6. .  
  7. <div id="footer">  
  8.   <p>&copy; niit student. All rights reserved.</p>  
  9. </div>  
HTML 5 Header and Footer:
  1. <header>  
  2.   <h1>Monday Times</h1>  
  3. </header>  
  4. .  
  5. .  
  6. .  
  7. <footer>  
  8.   <p>© niitstudy. All rights reserved.</p>  
  9. </footer>  

Menu Example

HTML 4 Menu:
  1. <div id="menu">  
  2.   <ul>  
  3.     <li>News</li>  
  4.     <li>Sports</li>  
  5.     <li>Weather</li>  
  6.   </ul>  
  7. </div>  
HTML 5 Menu:
  1. <nav>  
  2.   <ul>  
  3.     <li>News</li>  
  4.     <li>Sports</li>  
  5.     <li>Weather</li>  
  6.   </ul>  
  7. </nav>  

32) If I do not put <!DOCTYPE html> will HTML 5 work?

No, browser will not be able to identify that it is a HTML document and HTML 5 tags will not function properly.

33) What is the use of required attribute in HTML5?

It forces user to fill text on textfield or textarea before submitting form. It is used for form validation.
Example:
  1. Name: <input type="text" name="name" required>  

34) What are the new <input> types for form validation in HTML5?

The new input types for form validation are email, url, number, tel and date.
Example:
  1. <input type="email">