Advertisement
Guest User

Untitled

a guest
May 4th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.96 KB | None | 0 0
  1.  
  2.  
  3. sub checkFields
  4. {
  5. $count = 0;
  6. foreach my $key (keys %form)
  7. {
  8. if ($form{$key} eq ""){
  9. $errors{$key} = "Please Enter Somethin for $key";
  10. $count = 1;
  11. }
  12. else{
  13. ++$count;
  14. }
  15. print $count;
  16. }
  17. if ($count > 3){
  18. connectDB();
  19. }
  20. }
  21.  
  22. sub connectDB
  23. {
  24. $user = "a07";
  25. print $user;
  26. $pass = "176";
  27. $host = "db-mysql";
  28. $db   = "a07";
  29.  
  30. use DBI;
  31. $connectInfo = "dbi:mysql:$db:$host";
  32. $dbh = DBI->connect($connectInfo,$user,$pass);
  33. my $lookup = qq~INSERT INTO friends (name,sport) VALUES($form{'name'},$form{'sport'})~;
  34. $sth = $dbh->prepare($lookup);
  35. if($sth->execute()){print "EXECUTED";}
  36. $dbh->disconnect();
  37. }
  38. use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
  39. print qq~
  40.   <html><head><title>Student Survey</title>
  41.   <style type="text/css">
  42.   * {margin:0;padding:0}
  43.   #container{width:960px}
  44.   #myform{width:850px;margin-left:20px}
  45.   ul{list-style-type:none}
  46.   li{margin:10px}
  47.   label{display:inline-block;width:190px;text-align:right;margin-right:10px}
  48.   input{width:250px}
  49.   .submit{margin-left:190px;float:left}
  50.   </style>
  51.   </head>
  52.   <body>
  53. ~;
  54.  
  55. sub displayForm
  56. {
  57. print qq~
  58. <div id="container">
  59. <div id="myform">
  60. <form action="aboutme.pl" method="GET">
  61. <fieldset>
  62. <legend>Student Survey</legend>
  63. <ul>
  64. <li><label>Full Name:</label><input type="text" name="name" value="$errors{'name'}" onclick="this.value='';" /></li>
  65. <li><label>Favourite Sport:</label><input type="text" name="sport" value="$errors{'sport'}" onclick="this.value='';"  /></li>
  66. <li><label>Favourite Seneca Course:</label><input type="text" name="course" value="$errors{'course'}" onclick="this.value='';" /></li>
  67. <li><label>Current GPA:</label><input type="text" name="gpa" value="$errors{'gpa'}" onclick="this.value='';" /></li>
  68. </ul>
  69. <ul>
  70. <li><button class="submit" type="submit">Send</button></li>
  71.         <li><button type="reset">Reset</button></li>
  72. </ul>
  73. ~;
  74. }
  75. sub closeHtml
  76. {print "</fieldset></form></div></div></body></html>"}
  77.  
  78. checkFields();
  79. displayForm();
  80. closeHtml();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement