Guest User

Untitled

a guest
Jan 26th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. CREATE TABLE users (
  2. user_id int NOT NULL AUTO_INCREMENT,
  3. user_type VARCHAR(20) NULL,
  4. creation_date TIMESTAMP NOT NULL,
  5. username VARCHAR(100) NOT NULL,
  6. account_password VARCHAR(255) NOT NULL,
  7. PRIMARY KEY (user_id)
  8. );
  9.  
  10. use strict;
  11. use warnings FATAL => 'all';# good for debugging, FATAL kills program so warnings are more identifiable
  12. use CGI qw/:standard/;
  13. use CGI::Carp qw(fatalsToBrowser); # good for debugging, sends info to browser
  14. use DBI;
  15. use DBD::mysql;
  16. use Digest::SHA qw(sha256);
  17.  
  18. print header, start_html;
  19. my $fName = param('firstName');
  20. my $lName = param('lastName');
  21. my $compName = param('compName');
  22. my $email = param('email');
  23. my $pswrd = param('password');
  24. my $cnfPswrd = param('confPassword');
  25. my $encpswrd = "";
  26.  
  27. #check passwords match, if not display error, and exit script
  28. if ($pswrd eq $cnfPswrd) {
  29. $encpswrd = sha256($pswrd);
  30. } else {
  31. print "Passwords did not match! refresh form!";
  32. exit;
  33. }
  34.  
  35. #database credentials, to be changed accordingly
  36. my $database = "intsystest";
  37. my $host = "localhost";
  38. my $user = "root";
  39. my $pw = "password";
  40. my $dsn = "dbi:mysql:$database:localhost:3306";
  41.  
  42. #connect to database
  43. my $dbh = DBI->connect($dsn, $user, $pw,
  44. { RaiseError => 1 }) or die "unable to connect:$DBI::errstrn"; # <- this line good for debugging
  45.  
  46. #create, prepare, execute query, disconnect from DB
  47. my $personsQuery = "INSERT INTO persons (first_name, last_name) VALUES (?,?)";
  48. my $compQuery = "INSERT INTO company (company_name) VALUES (?)";
  49. my $usersQuery = "INSERT INTO users (username, account_password) VALUES (?,?)";
  50.  
  51. my $sth = $dbh->prepare($personsQuery);
  52. $sth->execute($fName, $lName);
  53. $sth = $dbh->prepare($compQuery);
  54. $sth->execute($compName);
  55. $sth = $dbh->prepare($usersQuery);
  56. $sth->execute($email, $encpswrd);
  57. $dbh -> disconnect;
  58.  
  59. # additional processing as needed ...
  60.  
  61. print end_html;
  62.  
  63. DBD::mysql::st execute failed: Field 'user_id' doesn't have a default value at /usr/lib/cgi-bin/compSignUpDBCGI.pl line 44.
Add Comment
Please, Sign In to add comment