PHP SQLSTATE [23000]:完整性约束违规

时间:2014-11-21 20:26:24

标签: php mysql

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

SQLSTATE [23000]:完整性约束违规:1048列'idT_Inf'不能为空

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

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>

1 个答案:

答案 0 :(得分:0)

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

$cityTourIncluded定义在哪里?

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