fork download
  1. <?php
  2.  
  3.  
  4. $student = array();
  5. $example = array('firstName', 'lastName', 'sex', 'section', 'email', 'year', 'exams', 'isLocal');
  6.  
  7. foreach ($example as $field) {
  8. $student[] = $_POST[$field];
  9. }
  10.  
  11. try {
  12. $DHB = new PDO('mysql:host = localhost;dbname = sat', 'root', '');
  13. $STH = $DHB->prepare("SELECT email FROM students WHERE email = ?");
  14. $STH->bindparam(1, $email);
  15. $email = $_POST['email'];
  16. print_r($DHB);
  17.  
  18. if ($STH->execute()) {
  19. throw new PDOExpenition("Email is invalid.\n");
  20. } else {
  21. $STH = $DHB->prepare("INSERT into students (firstName, lastName, sex, section, email, year, exams, isLocal) values ($student[0], $student[1],
  22. $student[2], $student[3], $student[4], $student[5], $student[6], $student[7])");
  23. $STH->execute();
  24. }
  25. }
  26. catch (PDOExpenition $e) {
  27. echo "error";
  28. }
  29. ?>
Runtime error #stdin #stdout #stderr 0.01s 20568KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Notice:  Undefined index: firstName in /home/wyIWD3/prog.php on line 10
PHP Notice:  Undefined index: lastName in /home/wyIWD3/prog.php on line 10
PHP Notice:  Undefined index: sex in /home/wyIWD3/prog.php on line 10
PHP Notice:  Undefined index: section in /home/wyIWD3/prog.php on line 10
PHP Notice:  Undefined index: email in /home/wyIWD3/prog.php on line 10
PHP Notice:  Undefined index: year in /home/wyIWD3/prog.php on line 10
PHP Notice:  Undefined index: exams in /home/wyIWD3/prog.php on line 10
PHP Notice:  Undefined index: isLocal in /home/wyIWD3/prog.php on line 10
PHP Fatal error:  Uncaught exception 'PDOException' with message 'could not find driver' in /home/wyIWD3/prog.php:14
Stack trace:
#0 /home/wyIWD3/prog.php(14): PDO->__construct('mysql:host = lo...', 'root', '')
#1 {main}
  thrown in /home/wyIWD3/prog.php on line 14