私はPDO接続を使用してテーブルに 'id'を挿入するためのクラスを持っているので、セッション変数にidというフォームデータを格納する必要があります。クラスとオブジェクトを使用してセッションでフォームデータを保存する
<?php
session_start();
// this class is used to create connection with database
class Database
{
private $db_host = ‘localhost’;
private $db_user = ‘root’;
private $db_pass = ‘root’;
private $db_name = ‘test’;
public function connect() {
$db = new PDO('mysql:host=$db_host;dbname=$db_name;charset=utf8mb4', '$db_user', '$db_pass');
}
}
this class is used to insert the id in the table
class table1 extends Database
{
public function insert_info()
{
$sql = "insert into info(id) values ('?')";
$sql->bind_param("s", $id);
$sql->execute();
return true;
}
}
$_SESSION['campid']='camp1001';
$db = new table1(); // it is used to object of class table1.
$res=$db->insert_info();
?>
テーブルのセッション変数をどのように格納するか。
constructor()またはinsert_info()で$ idを使用するかどうかは、モデルの用途によって異なります。モデルをミラーリングテーブルに使用する場合、パラメータをメソッド呼び出しに含める必要があります。 modelがデータベーステーブルのレコード(行)を表す場合、コンストラクタで$ idを使用します。 – Siffer