7-12 web lab programs vtu

Upload: reshma-bj

Post on 02-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 7-12 Web Lab Programs vtu

    1/9

    7) Write a Perl program to display a digital clock which displays the current time of theserver.

    7.html

    Digital ClockClick here for digital clock

    7.cgi

    #!/usr/bin/perluse CGI':standard';print "refresh:1\n";print "Content-type:text/html \n\n";($s,$m,$h)=localtime(time);print "digit clock
    ";print "$s seconds $m minutes $h hours";

    8) Write a Perl program to insert name and age information entered by theuser into a table created using MySQL and to display the current contentsof this table.

    8.html

    Name :

    Age :

    8.cgi

    #!/usr/bin/perl

    use CGI':standard';

    use strict;

    use DBI;

    use CGI;use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

  • 8/10/2019 7-12 Web Lab Programs vtu

    2/9

    my $q=new CGI;

    my $nm=$q->param("pname");

    my $age=$q->param("age");

    my $db1="reshma";

    my $host="localhost";

    my $user="root";

    my $pwd="";

    my $db= DBI->connect("DBI:mysql:reshma",$user,$pwd,{RaiseError => 1,AutoCommit =>

    1}) or die "$DBI::errstr\n";

    my $st="insert into resh1 values ('$nm','$age')";

    $q=$db->prepare($st);

    $q->execute();

    $q=$db->prepare("select * from resh1");

    $q->execute();print "content-type: text/html \n\n",

    " Database Information",

    "",

    "Inserting Of Record Successful!!!",

    "User Information",

    "",

    "NAMEAGE";

    while(($nm,$age)=$q->fetchrow())

    {print "$nm$age";

    }

    $q->finish();

    $db->disconnect();

    print"";

    9) Write a PHP program to store current date-time in a COOKIE anddisplay the Last visited on date-time on the web page upon reopening of

    the same page

    9.html

    cookie

  • 8/10/2019 7-12 Web Lab Programs vtu

    3/9

    Cookie program





    Please Click Here For The Last Login Time


    9.php

    10) Write a PHP program to store page views count in SESSION, toincrement the count on each refresh, and to show the count on web page

  • 8/10/2019 7-12 Web Lab Programs vtu

    4/9

    10.html

    session

    Session Program



    Please Click Here




    10.php

    You Visited This

    11) Create a XHTML form with Name, Address Line 1, Address Line 2, andE-mail text fields. On submitting, store the values in MySQL table.Retrieve and display the data based on Name.

    11a.html

  • 8/10/2019 7-12 Web Lab Programs vtu

    5/9

    Program 11

    function disp()

    {

    document.location="11b.html";

    }

    Name:

    Address 1:

    Address 2:

    email:



    11b.html

    Program 11

    Name:< input type =text name="name">

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

    11a.php

    Search result

  • 8/10/2019 7-12 Web Lab Programs vtu

    6/9

    $add1=$_GET["add1"];

    $add2=$_GET["add2"];

    $email=$_GET["email"];

    $sql="INSERT INTO resh VALUES('$name','$add1','$add2','$email')";

    $res=mysql_query($sql);

    if(!$res)

    {

    die('could not enter data:'.mysql_error());

    }

    else

    echo "entered data successfully\n";

    mysql_close($link);

    ?>

    11b.php

    Book Information

    function disp1()

    {

    document.location="11b.html";

    }

  • 8/10/2019 7-12 Web Lab Programs vtu

    7/9

    while($row=mysql_fetch_row($result))

    {

    echo '';

    echo ''.$row[0].'';

    echo ''.$row[1].'';

    echo ''.$row[2].'';

    echo ''.$row[3].'';

    }

    echo '';

    }

    else echo 'Record not found';

    ?>

    12) Build a Rails application to accept book information viz. Accessionnumber, title, authors, edition and publisher from a web page and storethe information in a database and to search for a book with the titlespecified by the user and to display the search results with properheadings.

    CONNECT TO MySQL

    Launch the Rails Application.i. mysql -u root

    ii. create database P12_development;

    iii. use P12_development;

    iv. create table books (id int not null auto_increment,accno varchar(30) not null,title varchar(50) not null,author varchar(50) not null,edition varchar(20),publisher varchar(50),primary key(id));

    Type the command exit to exit the MySQL

    v. rails -d mysql P12

    vi. cd P12

  • 8/10/2019 7-12 Web Lab Programs vtu

    8/9

    vii. ruby script/generate scaffold Book accno:string title:stringauthor:string edition:string publisher:string

    viii. ruby script/generate controller main

    ix.

    Open the\\InstantRails-2.0-win\rails_apps\P12\app\controllers\main_controller.rb and add thefollowing code.

    class MainController < ApplicationControllerdef welcome

    @num_books = Book.countend

    def result@searchresults = Book.find(:all,:conditions => ["title =

    ?", params[:s]])end

    end

    X. ruby script/server

    copy this two files inside app/views/main

    Welcome template for books

    Total number of books =

    Enter the title:

    Welcome template for books

  • 8/10/2019 7-12 Web Lab Programs vtu

    9/9

    @author = b.author@edition = b.edition@publisher = b.publisher %>

    Entered book is

    Accn.NoTitleAuthorEditionPublisher

    Open the Web Browser and type the command:http://localhost:3000/booksfor inserting

    for seraching purpose

    http://localhost:3000/main/welcome

    http://localhost:3000/bookshttp://localhost:3000/main/welcomehttp://localhost:3000/main/welcomehttp://localhost:3000/books