【问题标题】:Save only specific part from dropdown taken from AD query仅保存从 AD 查询中获取的下拉列表中的特定部分
【发布时间】:2017-03-02 05:13:05
【问题描述】:

目前正在开发用户管理页面,其中包含名称、用户名、电子邮件和级别字段。除了 level 之外的所有字段都是从 AD 获得的。我设法将值保存到数据库中。但是,名称字段同时采用用户名和电子邮件字段。下拉菜单会显示名称,但会保存用户名和电子邮件。

<th align="right" scope="row">Select User</th>
<td><script type="text/javascript">
var $ = function(e){ return document.getElementById(e); }
var swap = function(val){
var arr = val.split("|");
document.getElementsByName('username')[0].value = arr[0];
document.getElementsByName('email')[0].value = arr[1];
}
</script>

<select name="name" id="name" class="reginput" onchange="swap(this.value)"    />
<option value="">Select User</option>

<?php
// Create connection
$con=mysqli_connect("localhost","root","","dbname");

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL:" . mysqli_connect_error();
}

//$result = mysqli_query($con, "SELECT name,Id FROM users");
$result = $this->Users_model->queryAD();

$options=$test;

//while ($row=mysqli_fetch_array($result)) {
for ($i=0; $i<$result["count"]; $i++) {
//$options .= '<option value="'.$row["name"].'">'.$row["name"].'  '.'</option>';

$options .= '<option value="'.$result[$i]["samaccountname"]  [0].'|'.$result[$i]["mail"][0].'">'.$result[$i]["displayname"][0].'   '.'</option>';



}

$options .= '</select>';


echo $options;

例如:

选择用户:Jane Doe 用户名:简 电子邮件:janed@yahoo.com 级别:管理员

用户将显示为 Jane | janed@yahoo.com 而不是 Jane Doe,但其他字段都可以。

This is the page for inserting users , the display is fine but Full Name wont be saved properly into DB

【问题讨论】:

  • 您面临的问题是什么?
  • @SandeshGupta 它不会将全名保存到数据库中,而是使用用户名和电子邮件。

标签: javascript php codeigniter active-directory


【解决方案1】:

它需要usernameemail 而不是Full name,因为你给的optionvalue$result[$i]["samaccountname"][0].'|'.$result[$i]["mail"][0]

将选项的值改为

$options .= '<option value="'.$result[$i]["displayname"][0].'">'.$result[$i]["displayname"][0].'   '.'</option>';

编辑

要向用户显示用户名和电子邮件,并将全名保存到数据库,请使用:

$options .= '<option value="'.$result[$i]["displayname"][0].'">"'.$result[$i]["samaccountname"]  [0].'|'.$result[$i]["mail"][0].'"</option>';

【讨论】:

  • 它保存全名,但用户名和电子邮件不会填充到各自的字段中。是否可以放置所有字段但只取全名?
  • 您的意思是要在选择一个选项时将所有三个字段都保存到数据库中?
  • 我已经为电子邮件和用户名设置了单独的文本框字段。它们工作正常,将电子邮件和用户名值插入数据库。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-15
  • 2022-07-25
  • 1970-01-01
  • 2019-03-07
相关资源
最近更新 更多