1
这是继续上一个问题(html/php/sql form with insert/update),因此请在HTML表单上使用它作为参考。当客户入住时,其客户的活动状态变为1,房间的房间变更为0,并创建入住记录。HTML表单插入在PHP和MySQL中不起作用
除此之外,还需要使用所有这些信息生成第一笔租金。 rent_occupancy_id通过lastInsertId()
的用户计算出来,因为最后插入的ID将是占用ID。
rent_cost是否产生,无论客户入住的好处是否。如果客户没有收益,那么rent_cost = 126.57英镑,但如果他们是rent_cost = 20.03英镑。 date_lastpaid
与客户的占用记录的start_date相同,并且date_due等于date_lastpaid
的前一周。
问题是没有创建出租记录,但其他记录等所有其他更改都正在创建。任何帮助将非常感激。
<?php
require("dbconnect.php");
//CLIENT
$id = $_POST['id'];
//UPDATES client's to 1/Yes to say that they're now an active client in JRH,
//where the selected client's ID is equal to :id
$stmt = $dbh->prepare("UPDATE client SET active = 1 WHERE client_id=:id");
$stmt->bindParam(':id', $id);
$stmt->execute();
//ROOM
$room_id = $_POST['room_id'];
$stmt = $dbh->prepare("UPDATE room SET room_vacant = 0 WHERE room_id = :room_id");
$stmt->bindParam(':room_id', $room_id);
$stmt->execute();
//OCCUPANCY
$id = $_POST['id'];
$room_id = $_POST['room_id'];
$start_date = $_POST['start_date'];
$stmt = $dbh->prepare("INSERT INTO occupancy (occupancy_client_id, occupancy_room_id, start_date) VALUES(:id, :room_id, :start_date)");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':room_id', $room_id);
$stmt->bindParam(':start_date', $start_date);
$stmt->execute();
//Working out Rent Cost
$id = $_POST['id'];
$stmt=$dbh->prepare("SELECT * FROM client WHERE client_id=:id");
$stmt->bindParam(':id', $id);
$stmt->execute();
$row = $stmt->fetch();
//Works out whether a client has benefits or not,
//and then uses this information to generate a cost of the rent
if ($row['benefits'] == '0') {
$rent_cost = "126.57";
} else{
$rent_cost = "20.03";
}
//RENT INSERT
//
//As the occupancy record is being created above
//and the rent table needs a rent_occupancy_id to join,
//then we use lastInsertId() in order to get that occupancy id
$rent_occupancy_id = $dbh->lastInsertId();
$date_lastpaid = $_POST['start_date']; //As the client hasn't made a payment yet,
//we say that their last payment was the date they joined
$date_due = strtotime($date_lastpaid);
$date_due = strtotime('+1 week', $date_due);
$date_due = date('Y/m/d', $date_due);
$stmt = $dbh->prepare("INSERT INTO rent (rent_occupancy_id, rent_cost, date_lastpaid, date_due) VALUES (:rent_occupancy_id, :rent_cost, :date_lastpaid, :date_due)");
$stmt->BindParam(':rent_occupancy_id', $rent_occupancy_id);
$stmt->BindParam(':rent_cost', $rent_cost);
$stmt->BindParam(':date_lastpaid', $date_lastpaid);
$stmt->BindParam(':date_due', $date_due);
$stmt->execute();
?>
哇哈哈哈,我真是个白痴。我喜欢编程这种有趣的东西的COS。我会确认你回答一旦它让我 – Jack 2015-03-02 17:51:19
:-)有时它发生:-) – Alex 2015-03-02 17:52:03
*嗯.... *确实很奇怪。我真的不希望这个人在这里聚会(哈哈),但在我自己的测试中,'bindParam'和'BindParam'确实有效。我确实在这个http://www.reddit.com/r/PHP/comments/2tue8i/a_little_help_with_pdo_prepare_and_bindparam/上找到了一篇文章,并指出它不应该有问题,但可能是一个问题。这是没有足够的文件记录,应该通知PHP.net的人。只是让你们都知道的一个旁注。顺便说一下,我不是在回答这个问题。 – 2015-03-02 18:08:01