|
||||
ok nie coding aku.
login.php Code:
<form action="logindo.php" method="POST">
<table border="1">
<tr bgcolor="#993399">
<td colspan="2">
<div align="center"><font color="#FFFFFF">Login</font></div></td>
</tr>
<tr>
<td width="114">Matrix Number</td>
<td width="174">:
<input name="matrix_no" type="text" id="matrix_no" /></td>
</tr>
<tr>
<td>Password</td>
<td>:
<input type="password" name="password" /> <input name="submit" type="submit" value="send" /></td>
</tr>
</table>
[ <a href="register.php">register</a>? ]
</form>
logindo.php Code:
<?php
session_start();
error_reporting(E_ALL);
// Connect to the database server
$dbcnx = mysql_connect('localhost', 'root', '')
or die('<p>Unable to connect to the database server at this time.<br />Error: ' . mysql_error() . '</p>');
// Select the huh database
mysql_select_db('profile')
or die('<p>Unable to locate the profile database at this time.<br />Error: ' . mysql_error() . '</p>');
$matrix_no = strip_tags(trim($_POST['matrix_no']));
$password = strip_tags(trim($_POST['password']));
$sql = "SELECT matrix_no, password, user_id
FROM userinfo
WHERE matrix_no = '$matrix_no'
AND password = '$password'
LIMIT 0,1";
$result = mysql_query($sql)
or die('<p>Unable to query the profile database at this time.<br />Error: ' . mysql_error() . '</p>');
$row = mysql_fetch_array($result);
echo '<p>sql: ' , $sql , '<br />Matrix Number: ' , $row['matrix_no'] , '<br />Password: ' , $row['password'] , '</p>';
if(mysql_num_rows($result) == 1) // mysql_num_rows() returns the record count from the query result. you want one (1) matching record to verify the login was successful.
{
$_SESSION['loggedin'] = 1; // Setting session var 'loggedin' to true
$_SESSION['user_id'] = $user_id;
header('Location:member.php');
exit;
}
else
{
header('Location:error.php'); // Redirect to error page, as a matching record was not found in the table.
exit; // always 'exit'
}
?>
erm... btul ke aku set session tu? dan ape coding yg perlu aku letak tuk setiap page for registration user je yg ble xs?
__________________
-Kh4|if4H^4|4m^m4y4- Akhirat=CAHAYA,Dunia=BAYANG2. Bile kite kejar cahaya,otomatik bayang2 folo |
|
||||
have you refer official PHP manual for SESSION help? There are explaination and example of code inside.
You can get it from http://www.php.net |
|
|||
i'll explain very very briefly here.
I assume that you already have a form for username and password which could be a html file. then when clicked on login the action should be pointing to a php file. In the php file u will do this: Firstly, check whether the username & password matched if yes then u have to start a session. Later, u have to create a session and store value into it. next, on every page you must start with session_start(); (only for those pages that requires login). after that, u put few lines of codes after the session_start() to check whether the session variable was having a value that you assigned during the first page (only for pages that requires login). if there is value continue else die(); so that the page will not be displayed. |
|
||||
Disini tutorial login, session dalam BM.
oleh sdr rokawa kalau tak silap.. Senang dan mudah difahami.. yang penting punyai ketajaman minda dan tahap sabar berusaha yang tinggi ![]() http://www.php.net.my/211-Membina-ha...an-laluan.html |
|
||||
ok.. alhamdulillah.. session dah success..
ok la nie bile user dah success login.. akan ada satu button tuk apply hostel.. just satu list down je... then bila dia submit, failed la... data tak masuk dlm databse.. FYI, aku just create satu table je.. and now just nak update + masukkan field (hostel) tadi tu je.. nie coding aku : apply.php Quote:
Quote:
Harap dapat membantu..
__________________
-Kh4|if4H^4|4m^m4y4- Akhirat=CAHAYA,Dunia=BAYANG2. Bile kite kejar cahaya,otomatik bayang2 folo |
|
||||
check syntax, agak berterabur sket la
1)kalau array tu jangan lupe letak ( " ) atau ( ' ), takpe kalau tak letak pun PHP akan assumed. sebaiknye letak la 2)lagi, kalau kita nak letak array dalam string. kene letak { } Code:
$sql="UPDATE userinfo SET hostel = '$hostel' WHERE matrix_no = '{$_SESSION['matrix_no']}'";
contohnye kalau dah guna "echo" , guna echo terus, takyah guna "print" 4)escape character ( \ ) jangan dilupakan
__________________
http://sidik.org/ |
|
||||
aku dah lama tak jenguk php ni.. dekat setengah tahun sbb sambg blaja. takde masa nk buat progg. tapi, kalau aku tak silap, kat applydo.php tu ko tak hold value yg ko pass dr prev page tuh.. kalau aku tak silap la.. kalau silap, sorry beb!
__________________
To follow the path: Look to the master, Follow the master, Walk with the master, See through the master, Become the master. |
|
||||
ok.. prob solve gak akhirnye..
fuh.. mencabar gak awal2 nak blaja nie.. ![]() aku tukar code jadi cam nie : Code:
$sql="UPDATE userinfo SET hostel = '$hostel' WHERE matrix_no = $_SESSION[matrix_no]";
__________________
-Kh4|if4H^4|4m^m4y4- Akhirat=CAHAYA,Dunia=BAYANG2. Bile kite kejar cahaya,otomatik bayang2 folo |
|
||||
well... session ni senang jer.. kalau faham concept dia.
hmm.. ni code paling simple untuk session.. ![]() if (!$_SESSION['username']) { include("login.php"); } else { include("page.php"); } hmm.. katakan.. lepas seseorang login.. dia akan diforward ke page page.php... kalau non member.. dia akan.. ke page.. login.php.. ni bukan code complex... ni untuk.. strict kan page ke member / non-member..:PLast edited by YajivMalhotra; 10-10-2004 at 03:21 PM. |
![]() |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| www.vivientheplay.org/main.htm | simmu | Websites Review and Suggestion | 8 | 17-05-2005 05:24 PM |
| php bleh run ngan pws kan? | therion | Website Programming | 34 | 27-01-2004 05:47 PM |
| Main Game kat sini | duwe | Websites Review and Suggestion | 2 | 25-12-2003 01:44 AM |
| cammane nak berinteract ngan cgi or ngan any file eg. text file | nos | Website Design | 7 | 12-08-2002 11:30 AM |
| jom main bola..... | donut | Mamak Stall | 1 | 24-06-2002 11:24 PM |
All times are GMT +8. The time now is 10:40 PM.
Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.














Linear Mode

