2016-07-01 3 views
0

このエラーが発生しました。すべての名前が正しいことを確認してください。何が問題なのですか?rsn列に何も追加されていないようです。周りを探索していて問題は分かっていますが、私の問題の原因は何か分かりませんし、注射可能な場合はPDOを使ってコードをコメントすることができます。あなたのエラー状態、Integrity constraint violation: 1048 Column 'rsn' cannot be null inとしてSQLSTATE [23000]:整合性制約違反:1048列

HTML

<form action="rsdenar.php" method="post"> 
    <div id="gold-calc"> 
     <div class="col-md-4"> 
      <label for="amount"><h3><i class="fa fa-database">&nbsp;Kolicina</i></h3></label> 
      <input type="text" class="form-control" id="amount" name="gpamount"> 
     </div> 
     <div class="col-md-4"> 
      <select class="form-control" style="margin-top:30px; width: 70%;" id="goldtype"> 
       <option value="0.5">RS3</option> 
       <option value="1.6">RS 07</option> 
      </select> 
     </div> 
     <div class="col-md-4"> 
      <label for="price"><h3><i class="fa fa-database">&nbsp;Cena</i></h3></label> 
      <input type="text" class="form-control" id="price"> 
     </div> 
     <div class="row" style="padding-top: 170px;"> 
      <label for="idrsn">RSN: </label> 
      <input type="text" class="form-control" id="idrsn" name="rsn" style="width: 40%"> 
     </div> 
     <div class="row"> 
      <label for="emailbuy">Email: </label> 
      <input type="text" class="form-control" id="emailbuy" name="email-nakup" style="width: 40%;"> 
     </div> 
     <div class="buy-order"> 
      <button type="submit" class="btn btn-primary"><a style="text-decoration: none" href="#"><h5 style="font-family: arial; font-size: 20px">NAKUP</h5></a></button> 
     </div> 
    </div> 
</form> 

PHP

<?php 

include 'php_includes/db_connect.php'; 

try { 

    $stmt=$conn->prepare("INSERT INTO purchase (rsn,email,amount,unique_id) 
     VALUES (:rsn, :email, :amount, :unique_id)"); 
    $stmt->bindParam(':rsn', $_POST['rsn']); 
    $stmt->bindParam(':email', $_POST['email-nakup']); 
    $stmt->bindParam(':amount', $_POST['gpamount']); 
    $stmt->bindParam(':unique_id', $_POST['unique_id']); 
    $stmt->execute(); 

}catch (exception $e){ 
    echo $e; 
} 


?> 

SQL

enter image description here

+0

(外部キーおよびその他の主キーを含む)をご購入のテーブル構造は何ですか? –

+0

@PerdeepSinghが更新されました – swipeales

+1

未定義の変数 '$ _POST ['unique_id']' –

答えて

1

、あなたはrsnの値がある場合は常にチェックする必要がありますので、あなたが試着する前に空ですテーブルのデータを読み込みます。あなたのPHPコードにこのようでこれを行うことができ

<?php 
// validation added here 
if(isset($_POST) && !empty($_POST['rsn'])) { 
    try { 

     $stmt=$conn->prepare("INSERT INTO purchase (rsn,email,amount,unique_id) VALUES (:rsn, :email, :amount, :unique_id)"); 
     $stmt->bindParam(':rsn', $_POST['rsn']); 
     $stmt->bindParam(':email', $_POST['email-nakup']); 
     $stmt->bindParam(':amount', $_POST['gpamount']); 
     $stmt->bindParam(':unique_id', $_POST['unique_id']); 
     $stmt->execute(); 

    }catch (exception $e){ 
     echo $e; 
    } 

} 
関連する問題