gpt4 book ai didi

PHP SQLSTATE[23000] : Integrity constraint violation

转载 作者:行者123 更新时间:2023-11-29 23:24:28 25 4
gpt4 key购买 nike

我不明白为什么会出现这样的错误,你能帮我吗?错误:
SQLSTATE[23000]:违反完整性约束:1048 列“名称”不能为空

SQLSTATE[23000]:违反完整性约束:1048 列“idT_Inf”不能为空

也许我需要更改数据库中的一些详细信息?是的,我为数据库中的每一列设置了“NOT NULL”条件,但我没有在表单中留下任何空白(来自Administrativni prostredi)为空。 Mb 你们中有些人遇到过这样的问题。预先感谢:)

PraceSDB.php:

     <?php
class Connection{
public function __construct(){
try{
$this->db = new PDO('mysql:host=localhost; dbname=brichevg','brichevg','wa1');
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
echo $e->getMessage();
}
}

public function addNote(){
$name= $_POST['tourName'];

$path= $_POST['path'];

$days= $_POST['days'];

$hotel=$_POST['hotel'];

$priceSingleRoom= $_POST['priceSingleRoom'];

$priceDoubleRoom= $_POST['priceDoubleRoom'];

$priceBreakfast= $_POST['priceBreakfast'];

$priceLunch= $_POST['priceLunch'];

$priceDinner= $_POST['priceDinner'];

$cityTourPrice= $_POST['priceTour'];

$totalTourPrice= $_POST['totalTourPrice'];

$date= $_POST['date'];

$sql_1= "INSERT INTO Tour_Info (name, path, Hotel, Price_of_single_room, Price_of_double_room, Price_of_breakfast,
Price_of_lunch, Price_of_dinner, City_tour, Total_tour_price, City_tour_price, Amount_of_days)
VALUES (:name, :path, :hotel, :priceSingleRoom, :priceDoubleRoom, :priceBreakfast, :priceLunch, :priceDinner, :cityTour,
:totalTourPrice, :cityTourPrice, :days ) ";

try{
$prep_1=$this->db->prepare($sql_1);
$prep_1->bindParam(":name",$name);
$prep_1->bindParam(":path",$path);
$prep_1->bindParam(":days",$days);
$prep_1->bindParam(":hotel",$hotel);
$prep_1->bindParam(":priceSingleRoom",$priceSingleRoom);
$prep_1->bindParam(":priceDoubleRoom",$priceDoubleRoom);
$prep_1->bindParam(":priceBreakfast",$priceBreakfast);
$prep_1->bindParam(":priceLunch",$priceLunch);
$prep_1->bindParam(":priceDinner",$priceDinner);
$prep_1->bindParam(":cityTour",$cityTourIncluded);
$prep_1->bindParam(":cityTourPrice",$cityTourPrice);
$prep_1->bindParam(":totalTourPrice",$totalTourPrice);
$prep_1->execute();

$res=$this->db->query('SELECT @@IDENTITY');
$row=$res->fetch(PDO::FETCH_ASSOC);
$idecko=$row[0];

}
catch(PDOException $e){
echo $sql_1 . "<br>" . $e->getMessage();
}




$sql_2="INSERT INTO Tour(idT_inf,date) VALUES (:idT_inf, :date)";


try{
$prep_2=$this->db->prepare($sql_2);
$prep_2->bindParam(":date",$date);
$prep_2->bindParam(":idT_inf",$idecko);
$prep_2->execute();
}
catch(PDOException $e){
echo $sql_2 . "<br>" . $e->getMessage();
}

}
}

Administrativni_prostredi.php:

    <?php
require('praceSDB.php');
$connection= new Connection();
if(isset($_POST['submitNewTour'])){
$connection->addNote();
}
?>


<html>
<head><Title>Administrative interface</title>
<meto charset="utf-8"/>
</head>
<body>
<h3>Add new tour</h3>


<form method="post" action="">
<p><label>Tour name:</label>
<input type="text",name="tourName"/>
</p>

<p><label>Tour path:</label>
<input type="text",name="path"/>
</p>


<p><label>Amount of days:</label>
<input type="text",name="days"/>
</p>


<p><label>Hotel:</label>
<input type="text",name="hotel"/>
</p>

<p><label>Hotel price(single room):</label>
<input type="text",name="priceSingleRoom"/>
</p>

<p><label>Hotel price(double room):</label>
<input type="text",name="priceDoubleRoom"/>
</p>

<p><label>Breakfast price:</label>
<input type="text",name="priceBreakfast"/>
</p>

<p><label>Lunch price:</label>
<input type="text",name="priceLunch"/>
</p>

<p><label>Dinner price:</label>
<input type="text",name="priceDinner"/>
</p>

<p><label>City tour price:</label>
<input type="text",name="priceTour"/>
</p>

<p><label>City tour included:</label>
Yes: <input type="radio" name="cityTour" value="yes" /> No:<input type="radio",name="cityTour" value="no"/>
</p>
<p><label>Tour price (transport,agency servise): </label>
<input type="text",name="totalTourPrice"/>
</p>

<p><label>Trip's date:</label>
<input type="text",name="date"/>
</p>

<input type="submit" value="submit" name="submitNewTour"/>

</form>


<h3>All actual tours</h3>

</body>
</html>

最佳答案

$prep_1->bindParam(":cityTour",$cityTourIncluded);`

$cityTourInclusiond 在哪里定义?

编辑:这似乎不是您的问题,但它显示了一个问题。如果您显示或记录了通知,您可能已经能够弄清楚这一点。因此,我猜您会显示其他通知和错误,以帮助您解决问题。

关于PHP SQLSTATE[23000] : Integrity constraint violation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27069729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com