我是PHP新手,正在为Web应用程序编写代码。登录和注册功能正常运行,但是我在使用会话ID将数据插入新表时遇到问题,该会话ID在用户注册时自动生成并存储在用户信息表中。这是有问题的功能:
public function buy($userid, $today_date, $mths, $curr_year, $threefifty, $twofifty, $onefifty, $hundred, $fifty, $t_amnt, $commsn){
$order = "INSERT INTO bakery_tbl (id, dys, mnths, three_fty, two_fty, one_fty, one_hundred, unit_fifty, amt, comm) VALUES ('$userid', '$today_date', '$mths', '$curr_year', '$threefifty', '$twofifty', '$onefifty', '$hundred', '$fifty', '$t_amnt', '$commsn')";
$ex_buy = $this->db->query($order) or die(mysqli_connect_error(). "Data cannot be inserted");
return $ex_buy;
}
这是实现:
<?php
session_start();
require 'BakeryModel.php';
$model = new BakeryModel();
if(isset($_POST['order'])){
$dy = $_POST['dy'];
$mnth = $_POST['mnth'];
$yr = $_POST['yr'];
$q1 = $_POST['q1'];
$q2 = $_POST['q2'];
$q3 = $_POST['q3'];
$q4 = $_POST['q4'];
$q5 = $_POST['q5'];
$a1 = $q1 * 350;
$a2 = $q2 * 250;
$a3 = $q3 * 150;
$a4 = $q4 * 100;
$a5 = $q5 * 50;
$total = $a1 + $a2 + $a3 + $a4 + $a5;
$total_comm = 15*$total/100;
$purchase = $model->buy($_SESSION['user_id'], $dy, $mnth, $yr, $a1, $a2, $a3, $a4, $a5, $total, $total_comm);
if($purchase){
header("location: appreciate.php");
}
}
if(isset($_POST['logout'])){
$model->log_out();
header("location: index.php");
}
?>
<!Doctype html>
//HTML code here.`
每当我尝试提交表单数据时,我都会收到错误号0。 N / B->注销功能正常运行。我还尝试从表单中回显值,它们都显示期望值,包括会话ID。