[英]SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'status' cannot be null
[英]SQLSTATE[23000]: Integrity constraint violation: 1048 Column
我收到此錯誤,我確保所有名稱正確並且idk出了什么問題,似乎在rsn列中未添加任何內容。 一直在搜索,我知道問題,但是我不知道是什么導致了我的問題,如果您可以注釋我的代碼(如果可以注入),那么將是第一次使用PDO。
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"> 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"> 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
,因此在嘗試在表中插入數據之前,您需要始終檢查rsn
的值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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.