PDO数据库错误

时间:2014-03-12 16:59:49

标签: php pdo

我有一个HTML表单,它应该从用户捕获详细信息,然后将它们保存在数据库中。如果一切都保存,那么它应该只显示注册的详细信息,如果没有,它应该说请再试一次。我已经尝试过了,但是当我填写表单后,它似乎无法正常工作,这是显示的错误消息。

**> Fatal error: Call to a member function execute() on a non-object in
> /home/educate/public_html/sheffieldhallam/process.php on line 46**

Process.php

<?php 
error_reporting(E_ALL); 
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);

$config = parse_ini_file("config/config.ini");
  try{
      $con = new PDO('mysql:host='.$config['host'].";dbname=".$config['database'].";charset=utf8",$config['username'],$config['password']);
  } catch (PDOException $e){
        header("Location: confirm.php?success=false");
        exit;
  }

  $con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);


      foreach ($_GET as $value) {
         if($value==""){
             header("Location: confirm.php?success=false");
             exit;
         };
      }
    $firstname =$_GET['firstname'];
    $familyname =$_GET['familyname'];
    $email = $_GET['email'];
    $mobile =$_GET['mobile'];
    $course =$_GET['course'];
    $country =$_GET['country'];
    $nationality =$_GET['nationality'];


    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         header("Location: confirm.php?success=false");
         exit;
    }

   $preparedQuery = $con->prepare("INSERT INTO sheffieldhallam (firstname,familyname,email,mobile,course,country,nationality)
       VALUES (:firstname,:familyname,:email,:mobile,:course,:country,:nationality)");
   $result = $preparedQuery->execute(array(
       ':firstname' => $firstname, 
       ':familyname' => $familyname,
       ':email' => $email,
       ':mobile' => $mobile,
       ':course' => $course,
       ':country' => $country,
       ':nationality' => $nationality
       )
   );

  $con =null;
  if ($result){
     header("Location: http://www.shu.ac.uk/international/");    
  } else {
     header("Location: confirm.php?success=false");
  }

0 个答案:

没有答案