Php 正在尝试获取客户端在从到模型中键入的$clientId
我正在努力将客户ID从表单中提取到模型中。我正在使用netbeans11.1和php7.4。我遵循某个教程,以下是我尝试过的,首先是我的模型,它扩展了定义数据库连接的基本模型:Php 正在尝试获取客户端在从到模型中键入的$clientId,php,Php,我正在努力将客户ID从表单中提取到模型中。我正在使用netbeans11.1和php7.4。我遵循某个教程,以下是我尝试过的,首先是我的模型,它扩展了定义数据库连接的基本模型: <?php class Clients_Model extends Model { function __construct() { parent::__construct(); $clientId = filter_input(INPUT_P
<?php
class Clients_Model extends Model {
function __construct() {
parent::__construct();
$clientId = filter_input(INPUT_POST, $clientId);
}
public function run($clientId = null){
$statement = $this->db->prepare("SELECT * FROM client WHERE clientId
= :clientId");
$statement->execute(array(':clientId' => $clientId));
$data = $statement->fetchAll();
print_r($data);
}
}
?>
这很明显,因为没有像前面提到的错误消息那样定义这样的变量。看
function __construct() {
parent::__construct();
$clientId = filter_input(INPUT_POST, $clientId);
}
您希望使用以前从未定义过的变量$clientId来定义$clientId。是否确实要在构造函数中包含clientId?似乎它放错了地方,因为它也从未在进一步的步骤中使用过。也许您想将其移动到run函数?确保$clientId不为null?在使用过滤器输入功能之前。。。在filter\u输入函数之前,$clientId的值是多少???$clientId来自视图中的表单,我试图通过此变量将客户端提供的值获取到模型中,对此我不是很确定,您能否帮助Pleasety打印$clientId的值并查看结果
<div id="content">
<h3>Client Booking</h3>
<form action="clients/run" method="post">
<label for="clientId">Client Id:</label><br>
<input type="text" name="clientId" id="clientId"><br>
<input type="submit" name="submit"><br>
</form>
</div>
<?php
class View {
function __construct() {
}
public function render($name, $same = false){
if ($same == true){
require 'views/' .$name. '.php';
}else{
require 'views/header.php';
require 'views/' .$name. '.php';
require 'views/footer.php';
}
}
}
?>
> Notice: Undefined variable: clientId in C:\xampp\htdocs\healthMentor\models\clients_model.php on line 8
Array ( )
function __construct() {
parent::__construct();
$clientId = filter_input(INPUT_POST, $clientId);
}