ButtonClick in CGI

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • savanm
    New Member
    • Oct 2006
    • 85

    ButtonClick in CGI

    Code:
    #! c:/perl/bin/perl.exe
    use CGI qw(:standard);
    use DBI;
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
    $dbh = DBI->connect("DBI:mysql:database=perldbi;host=localhost","root","");
    $sth = $dbh->prepare('select * from foo1');
    $sth->execute();
    print header;
    print start_html('Newgen');
    print h1("DBI SAMPLES");
    print "User NAME:	<input type='text' name='user'><br>";
    print "<input type='button' value='Login' name='login'>";
    if($sth->rows == 0) {
    	#print "No information for " . $R:lace;
    
    } else {
    	print "<table border=2>\n";
    	while( $resptr = $sth->fetchrow_hashref() ) {
    		print "<tr>";
    		print "<td>" . $resptr->{"usrid"};
    		print "<td>" . $resptr->{"pass"};
    		print "\n";
    		print "<\/tr>";
    	}
    	print "</table>\n";
    }
    
    $dbh->disconnect;
    print end_html;
    Hi i have a code like that,

    For this I have One Textbox and Button

    IF am enter the values in that textbox and when am clicking that button,

    The particular record in the text box must be insert into the tables.

    ThanX
    Last edited by miller; Apr 5 '07, 05:35 PM. Reason: Code Tag and ReFormatting
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    I can't help much with the database part of your question, but the <input type=button> tag will not send data back to your script, use an <input type=submit> button.

    Comment

    • savanm
      New Member
      • Oct 2006
      • 85

      #3
      Hi Kevin,

      I will use <input type="submit"> instead of <input type="button">

      So please Give me a further way to solve this problem

      Thanx

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Originally posted by savanm
        Hi Kevin,

        I will use <input type="submit"> instead of <input type="button">

        So please Give me a further way to solve this problem

        Thanx

        Sorry my database skills are minimal.... to say the least. I can't help with that part your question.

        Comment

        • savanm
          New Member
          • Oct 2006
          • 85

          #5
          insert a element when sum event is occured

          Hi all,

          Code:
          #! c:/perl/bin/perl.exe
          
          use CGI qw(:standard);
          use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
          use DBI;
          
          use strict;
          
          my $dbh = DBI->connect("DBI:mysql:database=perldbi;host=localhost","root","");
          my $sth = $dbh->prepare('select * from test');
          $sth->execute();
          
          print header;
          print start_html('Newgen Imaging Systems(P) Ltd.,');
          $dbh->do("insert into test values('nav','hai')");
          print h1("Hello world");
          
          if($sth->rows == 0) {
          	print h1("YES");
          
          } else {
          	print h4("This is available table\n");
          	print "<table border=2>\n";
          	while(my $resptr = $sth->fetchrow_hashref) {
          		print "<tr>";
          		print "<td>". $resptr->{"name"};
          		print "<td>". $resptr->{"pass"};
          		print "\n";
          		print "<\/tr>";
          	}
          	print "<\/table>\n";
          }
          print "<br><input type='text' name='usrtxt'>";
          print "<br><input type='text' name='passtxt'>";
          print "<br><input type='submit' name='logbtn' value ='Insert' OnClick='Insert()'>";
          print "\t\t";
          print "<input type='submit' name='logbtn' value ='Clear'>";
          
          $dbh->disconnect;
          print end_html;
          
          #function Insert(){
          	#$d = $dbh->do("insert into test values('nav','hai')");
          #}
          I have a code like that

          For that i want to insert a element in the textbox to database when

          the button is clicked

          Thanx in advance
          Last edited by miller; Apr 8 '07, 01:11 AM. Reason: Code Tag and ReFormatting

          Comment

          Working...