我不明白为什么会出现这样的错误,你能帮帮我吗?错误:
SQLSTATE[23000]:完整性约束冲突:1048 列"name"不能为空
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);`
$cityTourIncluded
在哪里定义?
编辑:这似乎不是您的问题,但它显示了问题。 如果您显示或记录了通知,您可能已经能够弄清楚这一点。 所以我猜你会有其他通知和错误显示出来,让你陷入你的问题。