我有一个用户可以登录的系统,可以选择该事件并保存到数据库中。
然而,问题是我只能设置一个用户,你可以在save.php的第9行看到
所以我的问题是,如何将系统中的用户设置为自动,以便在其他用户登录时,数据将以其名称保存。问题是因为登录使用的是yii2框架而且这个select事件是使用html而事件的模型是使用gii,
以下是我的代码:
viewevents.php的代码
<?php
echo '<link href="../../css/style.css" rel="stylesheet"/>';
$event = get_events();
function get_events(){
include ("../config/connect.php");
$sql = "SELECT * FROM `events` order by event_id desc;";
if ($result = $dayahlatiff->query($sql)) { $in = 0;
while ($row = $result->fetch_assoc()) {
$new_res[$in] = $row;
$in++;
}
$result->free();
}
return isset($new_res)?$new_res:array();
}
$this->title = 'View Events';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $in = 1;
if (!empty($event)) {
include 'events.php';
}
?>
save.php的代码
<?php
session_start();
if(isset( $_SESSION["id_"])){
// $hh = $_SESSION["id_"];
// die($hh);
}
require("../../../vendor/yiisoft/yii2/Yii.php");
$user = "dayahlatiff";
//$user = Yii::$app->user->identity->username;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
if(isset($_POST["save"])){
include ("../../config/connect.php");
$where = $_POST["where"];
$list = $_POST["check_list"];
if(empty($list)){
header("Location: ".$where);
}else {
$done = true;
for($s = 0; $s<sizeof($list); $s++){
$event = $list[$s];
$sql = "INSERT INTO `selectevents` (`user_id`, `username`, `event_title`) VALUES (NULL, '$user', '$event');";
if($dayahlatiff->query($sql) === FALSE){
$event = false;
}
}
header("Location: ".$where);
}
}
答案 0 :(得分:0)
我建议您获取一些有关
的信息使用yii2及其文档获得一点点熟悉。
此代码是纯PHP,在Yii2等框架中,没有包含文件或连接到这样的数据库的东西。
仔细查看This Url中的Yii2文档,并尝试使用Yii2结构下的可用概念进行编码。确保你熟悉这些概念并试图忘记旧式的本机PHP编程。