HTML表单插入不能在PHP和MySQL中使用 [英] HTML form insert not working in PHP and MySQL

查看:75
本文介绍了HTML表单插入不能在PHP和MySQL中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接下来从上一个问题开始( html / php / sql表单与插入/更新),所以使用它在HTML表单上引用。当客户入住时,其客户的活动状态变为1,房间的房间变更为0,并创建入住记录。

除此之外,第一笔租金需要使用所有这些信息生成。 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);

//客户端
$ id = $ _POST ['id'];
//更新客户端为1 /是说他们现在是JRH中的活动客户端,
//所选客户端ID等于: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();

//计算租金成本
$ id = $ _POST ['id'];
$ stmt = $ dbh-> prepare(SELECT * FROM client WHERE client_id =:id);
$ stmt-> bindParam(':id',$ id);
$ stmt-> execute();
$ row = $ stmt-> fetch();
//计算出客户是否有收益,
//然后使用这些信息产生租金
的成本如果($ row ['benefits'] ==' 0'){
$ rent_cost =126.57;
} else {
$ rent_cost =20.03;
}


//租用插入
//
//当占用记录创建在
上方//租金表需要一个rent_occupancy_id加入,
//然后我们使用lastInsertId()以获得占用ID
$ rent_occupancy_id = $ dbh-> lastInsertId();
$ date_lastpaid = $ _POST ['start_date']; //由于客户尚未付款,所以
//我们说他们的最后一笔付款是他们加入
$ 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();
?>


解决方案

只需将<$ c $改成小写首字母c> bindParam();

  $ 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();


This follows on from a previous question (html/php/sql form with insert/update) so use that for reference on the HTML form. When a client moves in, their client's active is changed to 1, the room's room_vacant is changed to 0, and an occupancy record is made.

As well as this, the first rental payment needs to be generated using all this information. The rent_occupancy_id is worked out through the user of lastInsertId(), as the last inserted id would've been the occupancy ID.

The rent_cost is generated whether the client moving in is on benefits on not. If a client is not on benefits, then the rent_cost = £126.57 but if they are then rent_cost = £20.03. The date_lastpaid is the same as the start_date of the client's occupancy record and the date_due is equal to a week ahead of the date_lastpaid.

The problem is that a rent record is not being created yet all the other changes for the other records etc. are being made. Any help would be much appreciated.

<?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();
?>

解决方案

just change to lowercase first letter in bindParam();

$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();

这篇关于HTML表单插入不能在PHP和MySQL中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆