Php 如何按会话显示基于用户id的用户名
我这里有一个问题,我想在员工输入其员工id后显示员工姓名。My index.php将显示员工姓名,但它不起作用。欢迎后这里的问题显示资源id 4 我的桌子: index.php: 请有人帮帮我。。。谢谢。不要使用MYSQL,因为它已被弃用 然而,这个答案是基于你试图做什么 在此处找到的信息: 当您执行$rsstaff=mysql\u query$query\u rsstaff$sqlconnection时,您得到的是一个资源,而不是您所期望的从staff中选择staffname,其中staff.staffid=%s位于数据库的右侧 请尝试以下操作:Php 如何按会话显示基于用户id的用户名,php,sql,session,Php,Sql,Session,我这里有一个问题,我想在员工输入其员工id后显示员工姓名。My index.php将显示员工姓名,但它不起作用。欢迎后这里的问题显示资源id 4 我的桌子: index.php: 请有人帮帮我。。。谢谢。不要使用MYSQL,因为它已被弃用 然而,这个答案是基于你试图做什么 在此处找到的信息: 当您执行$rsstaff=mysql\u query$query\u rsstaff$sqlconnection时,您得到的是一个资源,而不是您所期望的从staff中选择staffname,其中staff.
$result = mysql_query($query_rsstaff, $sqlconnection);
$rsstaff = mysql_fetch_assoc($result);
然后
然后使用您的代码。当您这样做时,您将打印出MySQL查询资源$rsstaff。这种输出没有明显的形式,所以PHP只是告诉您它是一种资源,而不是任何更有意义的东西。这就是你看到的输出
您打算打印$rowrstaff的一个元素,可能是staffname元素
因此:
. 它们不再得到维护。看到了吗?改为了解,并使用or-将帮助您确定是哪一个。好的,但您更改其变量名的方式非常混乱。但此代码由软件提供。。我刚刚点击了dreamweaver上的记录集,它被编码了。。每当我进行更改时,它都会提醒javascript有错误。。那怎么办呢?非常感谢。!!!它正在工作!!!!:D@Nurul:请在您离开时填写一份客户满意度表。
<?php require_once('Connections/sqlconnection.php');
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
$colname_rsstaff = $_SESSION['staffid'];
if (isset($_GET['staffid'])) {
$colname_rsstaff = $_GET['staffid'];
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "login.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_sqlconnection, $sqlconnection);
$query_rsstaff = sprintf("SELECT staffname FROM staff WHERE staff.staffid = %s", GetSQLValueString($colname_rsstaff, "text"));
$rsstaff = mysql_query($query_rsstaff, $sqlconnection) or die(mysql_error());
$row_rsstaff = mysql_fetch_assoc($rsstaff);
$totalRows_rsstaff = mysql_num_rows($rsstaff);
?>
<title>Sistem Pengurusan Stok</title>
<center>
<form name="form1" method="POST" action="">
<table width="633" height="431" border="1">
<tr>
<td height="124" colspan="2" align="right"><?php include 'header.php'?>
<p><?php echo date("d-m-y")."<br>";?></p></td>
</tr>
<tr>
<td width="167" height="262"><?php include 'menu.php'?></td>
<td width="450" align="center"><p>Welcome
<?php echo $rsstaff?>
</p>
<p><a href="<?php echo $logoutAction ?>">Log out </a></p>
<p><a href="<?php echo $logoutAction ?>"> </a></p></td>
</tr>
<tr>
<td height="37" colspan="2"></td>
</tr>
</table>
</form>
</center>
<? session_destroy()?>
<?php
mysql_free_result($rsstaff);
?>
$result = mysql_query($query_rsstaff, $sqlconnection);
$rsstaff = mysql_fetch_assoc($result);
Welcome <?php echo $rsstaff["staffname"]; ?>
$rsstaff = mysql_result(mysql_query($query_rsstaff),0);
<?php echo $row_rsstaff["staffname"] ?>