亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何獲取只有當前登錄用戶之前輸入數據庫的數據?

如何獲取只有當前登錄用戶之前輸入數據庫的數據?

PHP
MMMHUHU 2022-07-22 16:58:22
我在開發方面相當新,因為在此之前我所做的只是管理數據庫。我想出了一個系統,它將擁有三種類型的用戶。行政管理用戶通過將用戶角色管理到登錄中,我已成功創建多用戶登錄頁面。但我目前遇到的問題是,我無法查看只有當前用戶之前提交的數據。例如,我有兩個用戶,Ariel 和 Lyla。我想要做的是,當 Ariel 登錄系統時,Ariel 只能看到她提交到數據庫的內容,至于目前,她可以看到提交的全部數據。我已經這樣做了$sql = "SELECT * FROM iirincidentmain_draft WHERE username='$_SESSION[user][username]'";但作為回報我得到了這個錯誤注意:數組到字符串的轉換我的完整代碼如下<?phpsession_start();//Checking User Logged or Notif(empty($_SESSION['user'])){ header('location:../index.php');}//Restrict admin or Moderator to Access user.php pageif($_SESSION['user']['role']=='admin'){ header('location:../admin/index.php');}if($_SESSION['user']['role']=='management'){ header('location:../management/index.php');}require_once("../db.php");?><div class="col-md-9 bg-white padding-2"><h3>Reports in Draft</h3>    <div class="row margin-top-20">      <div class="col-md-12">       <div class="box-body table-responsive no-padding">        <table id="example" class="table table-striped table-bordered" style="width:100%">      <thead>        <th>Incident Date</th>        <th>OPU Region Or Country</th>        <th>Incident Title</th>                              <th>Incident Category</th>        <th>Status</th>        <th>Draft IIR</th>        <th>Edit</th>      </thead>      <tbody>            <?php$sql = "SELECT * FROM iir_incidentmain_draft WHERE username='$_SESSION[user][username]'";  $result = $conn->query($sql);     if($result->num_rows > 0) {        while($row = $result->fetch_assoc())          {?>         <tr>有人可以給我建議嗎?
查看完整描述

1 回答

?
jeck貓

TA貢獻1909條經驗 獲得超7個贊

更改此行:

$sql = "SELECT * FROM iir_incidentmain_draft WHERE username='$_SESSION[user][username]'";

成為:

$sql = "SELECT * FROM iir_incidentmain_draft WHERE username='" . $_SESSION['user']['username'] . "'";

換句話說,您在會話中的鍵中缺少引號的錯字。在將數組值附加到字符串時,也有必要(我認為)使用點表示法。因此,您得到的字符串轉換錯誤可能是由于解析器僅$SESSION在嵌入外部雙引號時才看到的。

其他人可能會注意到你應該逃避這一切。轉義用戶名的有效方法是設置 sql 準備語句。


查看完整回答
反對 回復 2022-07-22
  • 1 回答
  • 0 關注
  • 73 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號