PDO插入查询错误

时间:2016-09-15 14:24:09

标签: php mysql json pdo

我正在尝试使用json和pdo将帖子插入表中。表的结构是这样的: enter image description here

和外国人的钥匙一样,外国人钥匙表不是空的。 enter image description here

我发帖并且一切正常,但是我认为查询有问题,因为我从json得到了错误回复,但我不能理解问题出在哪里,这是我的查询。

//json header and connection stuff
if ($_POST) {

var_dump($_POST);
  //Company Information
  $company_name           = $_POST['company_name'];
  $company_vat            = $_POST['company_vat'];
  $company_phone          = $_POST['company_phone'];
  $company_email          = $_POST['company_email'];
  $company_address        = $_POST['company_address'];
  $company_fax            = $_POST['company_fax'];
  $company_industry       = $_POST['company_industry'];
  $company_other          = $_POST['company_other'];

  try{
  $sql = 'INSERT INTO company_member(
          name,
          email,
          vat,
          phone,
          fax,
          address,
          industry_id,
          other_industry)
          VALUES(
          :company_name,
          :company_email,
          :company_vat,
          :company_phone,
          :company_fax,
          :company_address,
          :company_industry,
          :other_industry)';
  $stmt = $conn->prepare($sql);
  $stmt->bindValue(':company_name',$company_name,PDO::PARAM_STR);
  $stmt->bindValue(':company_email',$company_email,PDO::PARAM_STR);
  $stmt->bindValue(':company_vat',$company_vat,PDO::PARAM_INT);
  $stmt->bindValue(':company_phone',$company_phone,PDO::PARAM_STR);
  $stmt->bindValue(':company_fax',$company_fax,PDO::PARAM_STR);
  $stmt->bindValue(':company_address',$company_address,PDO::PARAM_STR);
  $stmt->bindValue(':company_industry',$company_industry,PDO::PARAM_INT);
  $stmt->bindValue(':other_industry',$company_other,PDO::PARAM_STR);

  $result = $stmt->execute();

  $count = $stmt->rowCount();

  // check for successfull registration
  if ($stmt->rowCount() == 1) {
   $response['status'] = 'success';
   $response['message'] = 'registered sucessfully, you may login now';
  } else {

    $response['status'] = 'error'; // could not register
   $response['message'] = 'could not register, try again later';
    } 
    }
  catch(PDOException $e){
       echo $e->getMessage();
  }

 }
 echo json_encode($response);

这是var_dump和响应的结果。我看不出我做错了什么。

array(8) {
  ["company_name"]=>
  string(6) "asfdas"
  ["company_vat"]=>
  string(5) "23122"
  ["company_phone"]=>
  string(3) "222"
  ["company_email"]=>
  string(21) "nicarashic@gmail.coma"
  ["company_address"]=>
  string(6) "dfasfa"
  ["company_fax"]=>
  string(5) "23233"
  ["company_industry"]=>
  string(1) "2"
  ["company_other"]=>
  string(3) "sss"
}
SQL: [402] INSERT INTO company_member(
          name,
          email,
          vat,
          phone,
          fax,
          address,
          industry_id,
          other_industry)
          VALUES(
          :company_name,
          :company_email,
          :company_vat,
          :company_phone,
          :company_fax,
          :company_address,
          :company_industry,
          :other_industry)
Params:  8
Key: Name: [13] :company_name
paramno=-1
name=[13] ":company_name"
is_param=1
param_type=2
Key: Name: [14] :company_email
paramno=-1
name=[14] ":company_email"
is_param=1
param_type=2
Key: Name: [12] :company_vat
paramno=-1
name=[12] ":company_vat"
is_param=1
param_type=1
Key: Name: [14] :company_phone
paramno=-1
name=[14] ":company_phone"
is_param=1
param_type=2
Key: Name: [12] :company_fax
paramno=-1
name=[12] ":company_fax"
is_param=1
param_type=2
Key: Name: [16] :company_address
paramno=-1
name=[16] ":company_address"
is_param=1
param_type=2
Key: Name: [17] :company_industry
paramno=-1
name=[17] ":company_industry"
is_param=1
param_type=1
Key: Name: [15] :other_industry
paramno=-1
name=[15] ":other_industry"
is_param=1
param_type=2
{"status":"error","message":"could not register, try again later"}

0 个答案:

没有答案