1

Hi folks I'm trying to do a simple CGI with 2 submit buttons, which do something on a database if you press them. Still I know I'm missing something because i can't seem to get it working.

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<center>
<form action="submit.pl" method="POST">
<input type="submit" name="Inicio" value="Inicio" id="Inicio" Inicio />
<input type="submit" name="Finaliza" value="Finaliza" id="Finaliza" Finaliza />
</form>
</center>
</body>
</html>

submit.pl

#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use CGI;

my $q = CGI->new;
my $dsn = "DBI:mysql:database=sms;host=10.0.0.1";
my $dbh = DBI->connect($dsn,"user","password123");


if ($q->param('Inicio')) 
    my $query = "insert into comienzo_programa (fecha, hora_inicio) values (CURDATE(),     CURTIME())";
$dbh->do($query);
} elsif ($q->param('Finaliza')) {
     my $query = "insert into comienzo_programa (hora_fin) values (CURTIME()) where   fecha=CURDATE()"; 
$dbh->do($query);
} 

I wonder what I am doing wrong. Thank you.

6
  • where fecha='CURDATE()', remove the single quote. Commented Dec 22, 2012 at 2:22
  • You have a </form> before your submit buttons. Commented Dec 22, 2012 at 2:40
  • Now It's starting to get into shape. It now displays the script once I click the button. Thank you. Commented Dec 22, 2012 at 2:43
  • Moved, submit.pl to cgi-bin folder. and configuring Apache. Commented Dec 22, 2012 at 2:50
  • One } is missing at line 12, after Inicio')) . Commented Dec 22, 2012 at 14:35

1 Answer 1

1

Your <form> is in the <head>, instead of the <body>, which looks peculiar.

Sign up to request clarification or add additional context in comments.

1 Comment

Fixed, on post and on site. Still, no luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.