Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display user name based on user id by session
    text
    copied!<p>I have a problem here which is I want to display the staff name after the staff has entered their staff id. My index.php will display the staff name, but it did not work. The problem here after welcome it display "Resource id #4". </p> <p><strong>My table :</strong> </p> <pre><code> CREATE TABLE `staff` ( `staffid` varchar(25) NOT NULL, `password` varchar(25) DEFAULT NULL, `staffname` varchar(50) DEFAULT NULL, `staffemail` varchar(50) DEFAULT NULL, `level` int(2) DEFAULT NULL, PRIMARY KEY (`staffid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 </code></pre> <p><strong>index.php :</strong></p> <pre><code>&lt;?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'])) &amp;&amp; ($_SERVER['QUERY_STRING'] != "")){ $logoutAction .="&amp;". htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_GET['doLogout'])) &amp;&amp;($_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; } } ?&gt; &lt;?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION &lt; 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); ?&gt; &lt;title&gt;Sistem Pengurusan Stok&lt;/title&gt; &lt;center&gt; &lt;form name="form1" method="POST" action=""&gt; &lt;table width="633" height="431" border="1"&gt; &lt;tr&gt; &lt;td height="124" colspan="2" align="right"&gt;&lt;?php include 'header.php'?&gt; &lt;p&gt;&lt;?php echo date("d-m-y")."&lt;br&gt;";?&gt;&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="167" height="262"&gt;&lt;?php include 'menu.php'?&gt;&lt;/td&gt; &lt;td width="450" align="center"&gt;&lt;p&gt;Welcome &lt;?php echo $rsstaff?&gt; &lt;/p&gt; &lt;p&gt;&lt;a href="&lt;?php echo $logoutAction ?&gt;"&gt;Log out &lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="&lt;?php echo $logoutAction ?&gt;"&gt; &lt;/a&gt;&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td height="37" colspan="2"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/center&gt; &lt;? session_destroy()?&gt; &lt;?php mysql_free_result($rsstaff); ?&gt; </code></pre> <p>Someone help me please... #Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload