 |
เกี่ยวกับการ Login แล้ว นำ Username มาโชว์คับ คือผมต้องการ ให้นำ Username มาโชว์ แทน Textbox |
|
 |
|
|
 |
 |
|
พอกรอก username passwd แล้ว ถ้าถูกต้องแล้วทำไม ไม่ให้วิ่งไปหน้า index สมาชิกอ่ะคับคือว่า ไปหน้า indexเดิม นี่มัน ไม่ได้มีการนำ user มาแสดงเลยอ่ะคับ หรือว่าทำแบบนี้ก็ได้นะคับ
if($username!=""){
echo "$username";
}else{
<form id="form1" name="form1" method="post" action="CheckMember.php">
48. <p align="left" class="style1"> <span class="style8">Username:</span><br />
49.
50. <input name="Username" type="text" id="Username" size="20" style="width:150px"/>
51. <br />
52. <span class="style8">Password:</span><br />
53.
54.<input name="Password" type="password" id="Password" size="22" style="width:150px"/>
55.<br />
56.<br />
57. <img src="Images/Forgot.png" width="77" height="31" lowsrc="Index.php" />
58.<input type="image" name="imageField" id="imageField" src="Images/Login.png" />
59.<label></label>
60.<br />
61. </p>
62. </form>
}
ถ้ายังไง ไม่ได้หรือไม่เข้าใจ add มาถามได้นะคับ [email protected]
|
 |
 |
 |
 |
Date :
2009-09-29 00:58:10 |
By :
heilender |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูนะครับ
session_start(); ไว้บรรทัดแรกของหน้า Index.php
แล้วเอา code นี้ไปวางแทน from
Code (PHP) Index.php
<?php if(empty($_SESSION['MM_UserName'])){?>
<form id="form1" name="form1" method="post" action="CheckMember.php">
<p align="left" class="style1"> <span class="style8">Username:</span><br />
<input name="Username" type="text" id="Username" size="20" style="width:150px"/>
<br />
<span class="style8">Password:</span><br />
<input name="Password" type="password" id="Password" size="22" style="width:150px"/>
<br />
<br />
<img src="Images/Forgot.png" width="77" height="31" lowsrc="Index.php" />
<input type="image" name="imageField" id="imageField" src="Images/Login.png" />
<label></label>
<br />
</p>
</form>
<? } else {echo "ยินดีตอนรับ คุณ "$_SESSION['MM_UserName']; } ?>
แล้วหน้า CheckMember.php ลองปรับเป็นแบบนี้ดู
Code (PHP)
<?php
// เริ่มการติดต่อฐานข้อมูล //
$host="localhost";
$db_username="root";
$db_password="";
$dbname="pailyndb";
$connect = mysql_connect($host,$db_username,$db_password);
if (isset($_POST['btnLogin'])) { // เช็ึคว่ามีการรับค่าจากการกดปุ่ม Login หรือไม่
if(empty($username)||empty($password)){ // ว่ามีกรอกข้อมูลครบหรือไม่
echo "<script>alert('กรุณากรอก Username และ Password ค่ะ');history.back();</script>";
exit();
}
// เช็ค user จากฐานข้อมูล //
mysql_select_db($dbname);
$strSQL = "SELECT * FROM member WHERE Username='".$_POST['Username']."' AND Password = '".$_POST['Password']."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$totalRows = mysql_num_rows($objQuery);
$rowLogin = mysql_fetch_array($objQuery);
if($totalRows == 1){ // เช็ค ว่ามี User ในฐานข้อมูลหรือไม่ ถ้าเท่ากับ 1 มี เมื่อมีให้สร้าง session
session_start();
$_SESSION['MM_UserName'] = $rowLogin['UserName'];
echo "<meta http-equiv='refresh' content='0;URL=Index.php'>";
}else{ // ไม่มี user นี้ในฐานข้อมูลแจ้งให้ทราบ แล้วกลับไปหน้า login ใหม่
echo "<meta http-equiv='Content-Type' content='text/html; charset=tis620' />";
echo "<script language='javascript'>alert('ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง กรุณาลองใหม่');</script>";
echo "<meta http-equiv='refresh' content='0;URL=form_login.php'>";
}
}
?>
ผิดถูกงัยแจ้งกันด้วยนะครับ
ลองเอาไปปรับใช้อย่างที่คุณต้องการดูครับ

|
 |
 |
 |
 |
Date :
2009-09-29 09:15:14 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากนะคับ
ผมลองเอาโค้ดของคุณ Rastafari ไปใช้แล้วมันขึ้นว่า
Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in d:\pailin\index2.php on line 67
คับ
และขอบคุณ คุณ heilender มากๆนะคับ ที่ช่วยแก้ดค้ดให้ผม แหะๆ
^ ^"
|
 |
 |
 |
 |
Date :
2009-09-29 14:29:17 |
By :
gungrave |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เว็บสวยอะ
|
 |
 |
 |
 |
Date :
2009-09-29 14:42:49 |
By :
danya |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วตกลงได้ยังครับ
ถ้ายังเอา code index2.php มาดูหน่อยครับ
|
 |
 |
 |
 |
Date :
2009-09-29 14:50:33 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Index2.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home</title>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
.style8 {font-family: Tahoma; font-size: 14px; }
.style9 {
font-family: "KT Wonderfool";
font-size: 24px;
color: #DB1D3E;
}
-->
</style>
</head>
<body>
<table width="955" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th height="250" colspan="7" align="left" valign="top" bordercolor="#E7EAEE" background="Images/Untitled-1.png" scope="col"><p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</th>
</tr>
<tr>
<th height="40" scope="row"><img src="Images/frame-top_th.png" width="222" height="62" /></th>
<td width="400" bgcolor="#DB1D3E"><div align="center"><a href="Index.php"><img src="Images/Bt_Home.png" width="113" height="42" border="0" /></a></div></td>
<td width="400" bgcolor="#DB1D3E"><div align="center"><a href="AboutUs.php"><img src="Images/Bt_About.png" width="113" height="42" border="0" /></a></div></td>
<td width="400" bgcolor="#DB1D3E"><div align="center"><a href="Menu.php"><img src="Images/Bt_Menu.png" width="113" height="42" border="0" /></a></div></td>
<td width="400" bgcolor="#DB1D3E"><div align="center"><a href="HowtoOrder.php"><img src="Images/Bt_Howto.png" width="113" height="42" border="0" /></a></div></td>
<td width="400" bgcolor="#DB1D3E"><div align="center"><a href="News.php"><img src="Images/Bt_News.png" width="113" height="42" border="0" /></a></div></td>
<td width="400" bgcolor="#DB1D3E"><div align="center"><a href="ContactUs.php"><img src="Images/Bt_Contact.png" width="113" height="42" border="0" /></a></div></td>
</tr>
<tr>
<th height="40" background="Images/frame-bg.png" scope="row">
<?php if(empty($_SESSION['MM_UserName'])){?>
<form id="form1" name="form1" method="post" action="CheckMember2.php">
<p align="left" class="style1"> <span class="style8">Username:</span><br />
<input name="Username" type="text" id="Username" size="20" style="width:150px"/>
<br />
<span class="style8">Password:</span><br />
<input name="Password" type="password" id="Password" size="22" style="width:150px"/>
<br />
<br />
<img src="Images/Forgot.png" width="77" height="31" lowsrc="Index.php" />
<input type="image" name="imageField" id="imageField" src="Images/Login.png" />
<label></label>
<br />
</p>
</form>
</th>
<? } else {echo "ยินดีตอนรับ คุณ "$_SESSION['MM_UserName']; } ?>
<td colspan="6" rowspan="2" align="left" valign="top" background="Images/frame0-bg[1].png"><p> </p>
<p> </p>
<p> </p>
<p> </p></td>
</tr>
<tr>
<th height="40" scope="row"><img src="Images/frame-bottom.png" width="222" height="70" /></th>
</tr>
<tr>
<th height="40" scope="row"><div align="left"> <a href="Register.php"><img src="Images/Regis.png" width="139" height="39" border="0" /></a></div></th>
<td colspan="6"> </td>
</tr>
<tr>
<th height="45" colspan="7" align="left" background="Images/bg-footer[2].png" scope="row"><span class="style9">
<MARQUEE onmouseover=stop(); onmouseout=start();>
<img src="Images/Footer(runner).png" width="350" height="24" />
</MARQUEE>
</span></th>
</tr>
</table>
</body>
</html>
|
 |
 |
 |
 |
Date :
2009-09-29 15:07:03 |
By :
gungrave |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูนะครับ
Code (PHP)
<? } else {echo "ยินดีตอนรับ คุณ ".$_SESSION['MM_UserName']; } ?>
ได้งัยแจ้งกันบ้างครับ
|
 |
 |
 |
 |
Date :
2009-09-29 15:30:52 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ละคับ ขอบคุณมากนะครับ
แต่พอ Login ไปแล้ว มันไม่ยอมกลับไปหน้า Index2 อะคับ
มันไปอยู่ที่ CheckMember2.php ของผมอะคับ
ช่วยดูให้หน่อยนะครับ
|
 |
 |
 |
 |
Date :
2009-09-29 16:12:09 |
By :
gungrave |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
code ตามนี้หรือป่าวครับ
ลองดูตอน login ผ่านอ่ะครับ ว่าจะให้ไปไหน
Code (PHP)
<?php
// เริ่มการติดต่อฐานข้อมูล //
$host="localhost";
$db_username="root";
$db_password="";
$dbname="pailyndb";
$connect = mysql_connect($host,$db_username,$db_password);
if (isset($_POST['btnLogin'])) { // เช็ึคว่ามีการรับค่าจากการกดปุ่ม Login หรือไม่
if(empty($username)||empty($password)){ // ว่ามีกรอกข้อมูลครบหรือไม่
echo "<script>alert('กรุณากรอก Username และ Password ค่ะ');history.back();</script>";
exit();
}
// เช็ค user จากฐานข้อมูล //
mysql_select_db($dbname);
$strSQL = "SELECT * FROM member WHERE Username='".$_POST['Username']."' AND Password = '".$_POST['Password']."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$totalRows = mysql_num_rows($objQuery);
$rowLogin = mysql_fetch_array($objQuery);
if($totalRows == 1){ // เช็ค ว่ามี User ในฐานข้อมูลหรือไม่ ถ้าเท่ากับ 1 มี เมื่อมีให้สร้าง session
session_start();
$_SESSION['MM_UserName'] = $rowLogin['UserName'];
echo "<meta http-equiv='refresh' content='0;URL=Index.php'>"; // ถ้า login ผ่านจะให้ไปไหนก็ใส่ตรงนี้อ่ะครับ
}else{ // ไม่มี user นี้ในฐานข้อมูลแจ้งให้ทราบ แล้วกลับไปหน้า login ใหม่
echo "<meta http-equiv='Content-Type' content='text/html; charset=tis620' />";
echo "<script language='javascript'>alert('ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง กรุณาลองใหม่');</script>";
echo "<meta http-equiv='refresh' content='0;URL=form_login.php'>";
}
}
?>
|
 |
 |
 |
 |
Date :
2009-09-29 16:32:46 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตามนั้นเลยคับ
ยังเป็นเหมือนเดิมอยู่เลย
|
 |
 |
 |
 |
Date :
2009-09-29 16:44:38 |
By :
gungrave |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้า login ผ่านจะให้ไปไหนครับ index.php หรือ index2.php ครับ
ไม่น่าจะค้่างอยู่ที่ CheckMember2.php
|
 |
 |
 |
 |
Date :
2009-09-29 17:00:53 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บรรทัดนี้ใช่ป่ะคับ
echo "<meta http-equiv='refresh' content='0;URL=Index.php'>"; // ถ้า login ผ่านจะให้ไปไหนก็ใส่ตรงนี้อ่ะครับ
ผมเปลี่ยนตรง URL ให้เป็น Index2.php แล้วก็ยังไม่ได้คับ Index.php ก็ยังไม่ได้
|
 |
 |
 |
 |
Date :
2009-09-29 17:05:11 |
By :
gungrave |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ผมลองแล้วนะครับ
เด่วลองเอาไปปรับใช้ดู
Code (PHP) : index2.php
<?php session_start();?>
<!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=utf-8" />
<title>index2.php</title>
</head>
<body>
<?php if($_SESSION['MM_UserName']==""){?>
<form id="form1" name="form1" method="post" action="CheckMember2.php">
<p align="left" class="style1"> <span class="style8">Username:</span><br />
<input name="Username" type="text" id="Username" size="20" style="width:150px"/>
<br />
<span class="style8">Password:</span><br />
<input name="Password" type="password" id="Password" size="22" style="width:150px"/>
<br />
<br />
<label>
<input type="submit" name="btnLogin" id="btnLogin" value="login" />
</label>
<label></label>
<br />
</p>
</form>
</th>
<? } else {echo "ยินดีตอนรับ คุณ ".$_SESSION['MM_UserName']; } ?>
</body>
</html>

Code (PHP) : CheckMember2.php
<?php
// เริ่มการติดต่อฐานข้อมูล //
$hostname = "localhost";
$database = "pailyndb";
$username = "root";
$password = "1234";
$conn = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_query("SET NAMES tis620");
if (isset($_POST['btnLogin'])) { // เช็ึคว่ามีการรับค่าจากการกดปุ่ม Login หรือไม่
if($_POST['Username']=="" || $_POST['Password']==""){ // ว่ามีกรอกข้อมูลครบหรือไม่
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
echo "<script>alert('กรุณากรอก Username และ Password ค่ะ');history.back();</script>";
exit();
}
// เช็ค user จากฐานข้อมูล //
mysql_select_db($database);
$strSQL = "SELECT * FROM member WHERE Username='".$_POST['Username']."' AND Password = '".$_POST['Password']."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$totalRows = mysql_num_rows($objQuery);
$rowLogin = mysql_fetch_array($objQuery);
if($totalRows == 1){ // เช็ค ว่ามี User ในฐานข้อมูลหรือไม่ ถ้าเท่ากับ 1 มี เมื่อมีให้สร้าง session
session_start();
$_SESSION['MM_UserName'] = $rowLogin['Username'];
echo "<meta http-equiv='refresh' content='0;URL=index2.php'>"; // ถ้า login ผ่านจะให้ไปไหนก็ใส่ตรงนี้อ่ะครับ
}else{ // ไม่มี user นี้ในฐานข้อมูลแจ้งให้ทราบ แล้วกลับไปหน้า login ใหม่
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
echo "<script language='javascript'>alert('ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง กรุณาลองใหม่');</script>";
echo "<meta http-equiv='refresh' content='0;URL=index2.php'>";
}
}
?>


ลองเอาไปปรับใช้นะครับ
ได้ผลงัยก็แจ้งกันด้วย
ได้เวลากลับบ้านแล้วละครับ ผม   
|
 |
 |
 |
 |
Date :
2009-09-29 17:43:05 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากนะคับ เดี๋ยวผมลองเอาไปใช้ดู 
|
 |
 |
 |
 |
Date :
2009-09-29 17:49:20 |
By :
gungrave |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ผลยังไงก็แจ้งด้วยนะครับ

|
 |
 |
 |
 |
Date :
2009-09-30 08:47:08 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php session_start();?>
<!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=utf-8" />
<title>index2.php</title>
</head>
<body>
<?php if($_SESSION['MM_UserName']==""){?>
<form id="form1" name="form1" method="post" action="CheckMember.php">
<p align="left" class="style1"> <span class="style8">Username:</span><br />
<input name="Username" type="text" id="Username" size="20" style="width:150px"/>
<br />
<span class="style8">Password:</span><br />
<input name="Password" type="password" id="Password" size="22" style="width:150px"/>
<br />
<br />
<label>
<input type="submit" name="btnLogin" id="btnLogin" value="login" />
</label>
<label></label>
<br />
</p>
</form>
</th>
<? } else {echo "ยินดีตอนรับ คุณ ".$_SESSION['MM_UserName']; } ?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2014-05-28 10:34:53 |
By :
sing |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

<?php
$user = $_SESSION["login"]; //ตัวแปร $user มาจาก การ login
echo "สวัสดีคุณ $user[Firstname]";
?>

|
 |
 |
 |
 |
Date :
2014-05-28 11:21:43 |
By :
banditt |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|