หน้า Login เขียนด้วย dreamwever จะเอาชื่อที่ login มาแสดงได้อย่างไร
ท่านผู้รู้ช่วยดูให้หน่อยนะครับ
Code (PHP)
<?php require_once('Connections/connecttion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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_connecttion, $connecttion);
$query_Recordset1 = "SELECT * FROM hos_name ORDER BY hos_id ASC";
$Recordset1 = mysql_query($query_Recordset1, $connecttion) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['user'])) {
$loginUsername=$_POST['user'];
$password=$_POST['passwd'];
$MM_fldUserAuthorization = "accesslavel";
$MM_redirectLoginSuccess = "index.php";
$MM_redirectLoginFailed = "loginfail.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_connecttion, $connecttion);
$LoginRS__query=sprintf("SELECT `user`, passwd, accesslavel FROM member WHERE `user`=%s AND passwd=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $connecttion) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'accesslavel');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title><?php echo $row_Recordset1['hos_name']; ?> </title>
<style type="text/css">
<!--
body {
background-image: url();
background-repeat: no-repeat;
}
.style8 {
font-family: "MS Sans Serif";
font-weight: bold;
color: #0000FF;
font-size: 24px;
}
.style13 {color: #FF66FF; }
.style17 {font-size: 14px; font-weight: bold; font-family: "MS Sans Serif"; color: #0000FF; }
.style19 {font-size: 12px; font-weight: bold; font-family: "MS Sans Serif"; color: #0000FF; }
-->
</style>
<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
} }
//-->
</script>
</head>
<body>
<form ACTION="<?php echo $loginFormAction; ?>" method="POST" name="form1" id="form1" onsubmit="MM_validateForm('user','','R','passwd','','R');return document.MM_returnValue">
<p align="center"><span class="style8"><span class="style13"><?php echo $row_Recordset1['hos_name']; ?></span></span></p>
<table width="500" height="222" border="1" align="center" cellspacing="0" bordercolor="#087ED8">
<tr>
<td background="images/login.gif"><br />
<table width="250" border="0" align="center">
<tr>
<td><div align="right"><span class="style13"><span class="style17">ชื่อผู้ใช้</span></span></div></td>
<td><input name="user" type="text" class="style13" id="user" /></td>
</tr>
<tr>
<td><div align="right"><span class="style13"><span class="style17">รหัสผ่าน</span></span></div></td>
<td><input name="passwd" type="password" class="style13" id="passwd" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="เข้าสู่ระบบ" /></td>
</tr>
<tr>
<td colspan="2"><span class="style19">พัฒนาโปรแกรมโดย xxxxxxxx</span></td>
</tr>
<tr>
<td colspan="2"><div align="center"><span class="style19">xxxxxxxx</span></div></td>
</tr>
<tr>
<td colspan="2"><div align="center"><span class="style19">xxxxxxxx</span></div></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Tag : PHP
Date :
2011-06-03 13:42:38
By :
addy_it
View :
1273
Reply :
11
เอามาจาก session ไงครับ $_SESSION['MM_Username'] = $loginUsername;
Date :
2011-06-03 14:49:13
By :
Chaan
ใช้ select * from tbl_name where ' ".$_SESSION['sessionid ของคุณ']." '
แล้ว คิวรี่ เรียก name ออกมาครับ
Date :
2011-06-03 14:55:00
By :
ManGal49
เอามาจาก SESSION อะครับ เพราะเข้าเว็บมาแต่ละครั้งมีการกรอก ID ก็เอาตัวแปรไปเก็บค่าใน SESSION
ทีนี้ก็เรียกจาก SESSION ได้ตลอดละครับ สำหรับชื่อ ID
Date :
2011-06-03 15:06:45
By :
MC
ขอบคุณ มากครับ ทำได้แล้วครับ ตามคำแนะนำแรก อยากบอกต่อคนที่อยากทำแบบผมนะครับ
เอาโค้ดด้านล่างไปไว้บนสุดของหน้าที่จะให้แสดง ชื่อที่ login ครับ
<?php
session_start(); //เรียกฟังก์ชั่น session_start() เพื่อเริ่มใช้งาน session
?>
แล้วถ้าอยากให้แสดงตรงไหนก็ เอาโค้ดนี้ไปไว้ตรงนั้นครับ
<?php
echo $_SESSION['MM_Username'] ;
?>
แต่ท่านอื่นช่วยเสริมหน่อยนะครับ ถ้าผมจะดึงเอาชื่อเต็ม ของผู้ที่ login มาแสดงหละครับ ต้องเขียนโค้ดแบบไหนครับ
Date :
2011-06-03 15:10:41
By :
addy_it
ก็ต้อง select เรียกใช้ฐานข้อมูลก่อนไงครับ ใส่ where ไงครับ ^^
Date :
2011-06-03 15:21:09
By :
ManGal49
รบกวนคุณ ManGal หรือท่านไดก็ได้ครับ เขียนโค้ดเต็ม ๆ อย่างไรครับ รบกวนด้วยนะครับ
Date :
2011-06-03 15:44:01
By :
addy_it
Code (PHP)
<?
$link=mysql_connect("localhost","root","123456");
mysql_select_db("ntnbus");
mysql_query("set character set tis620");
$sql="select * from customer where cus_id='$_SESSION[sess_id]' ";
$result=mysql_query($sql);
while($row=mysql_fetch_object($result) )
{
echo " <img src='../images/icon_user.gif' width='30' height='30' /><div align='left'><span class='style15'> $row->cus_id ::: ยินดีต้อนรับ ::: </span></div>";
echo " <div align='center'><span class='style15'>คุณ $row->name $row->sname</span><br />";
}
?>
Date :
2011-06-03 15:56:16
By :
ManGal49
รุ่นใหญ่มาเอง ^^'
Date :
2011-06-03 17:00:12
By :
ManGal49
รบกวนอีกรอบนะครับ ผมเขียนแบบนี้แล้วมันไม่แสดงผลอะไร ไม่ฟ้อง eror อะไรเลยครับ ควรแก้ตรงไหนครับ ช่วยหน่อยครับ
Code (PHP)
$link=mysql_connect("localhost","root","123456");
mysql_select_db("ชื่อฐานข้อมูล");
mysql_query("set character set tis620");
$sql="select * from member where id='$_SESSION[MM_Username]' ";
$result=mysql_query($sql);
while($row=mysql_fetch_object($result) )
{
echo $row->fullname ;
}
?>
ในตาราง member ของผมมี id,user,passwd,fullname,level ครับ
Date :
2011-06-06 10:23:36
By :
addy_it
ลืมบอกไปครับ ผมต้องการเอา fullname มาแสดงครับ
Date :
2011-06-06 10:25:39
By :
addy_it
Load balance : Server 03