2016-07-01 2 views
0

이 오류가 발생합니다. 모든 이름이 정확하고 idk가 잘못되었는지 확인합니다. rsn 열에 아무 것도 추가되지 않은 것처럼 보입니다. 주변을 검색하고 문제를 알고 있지만 내 문제의 원인을 알 수 없으며 PDO를 처음 사용하는 경우 주사 할 수 있다고 내 코드에 주석을 달 수 있습니다.SQLSTATE [23000] : 무결성 제약 조건 위반 : 1048 Column

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은 오류 상태, Integrity constraint violation: 1048 Column 'rsn' cannot be null in로서

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; 
    } 

} 
관련 문제