logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > General
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 11-09-2006, 02:25 PM   #1
galileo
 
Join Date: Nov 2006
Posts: 8
Default Several Questions converning DW,PHP & MYSQL

Hello everybody,

I am happy to find this website as it helped me learning dreamweaver which i received a while ago

I have some questions/requests indeed concerning DW php and MYSQL .. here we go :


1) I want a simple way to make a Session system
2) it maybe related to "1", I have a login system .. i just want to get the username or the id of the logged in username in order to get his profile updated using a form and a record-set .. (btw, i searched the forum but didnt find my desire )

3) last question for now, How can i insert the text just as it was entered in the text area .. i mean if a person writes a paragraph, i want it to be "when retrieved" just like it was entered "as when a person press ENTER it doesnt work and i have to use
"

I hope anybody helps me getting started knowing that i have no idea about PHP language

Thanks in advance for your help and i hope i did not cause any disturbance..

Yours,
Galal
__________________
Trying to learn anything b4 college
galileo is offline   Reply With Quote
Old 11-10-2006, 05:27 PM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

how did you write the login system?

If you used dw to do this then you should have a session system already running

Dreamweaver uses the user_id as a unique identifyer and carrys that through the application or site. If you want to replace that with the user_id then this is a simple tweak to the login script

Quote:
3) last question for now, How can i insert the text just as it was entered in the text area .. i mean if a person writes a paragraph, i want it to be "when retrieved" just like it was entered "as when a person press ENTER it doesnt work and i have to use
"
if you are displaying the data to a page and not back to the form textarea you created then just wrap your variable in a nl2br() function befor you insert it in the database

example...

Code:
$text  = nl2br($_POST['textarea']);
this will replace \n with
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 11-10-2006, 05:34 PM   #3
galileo
 
Join Date: Nov 2006
Posts: 8
Default

Thanks for your reply my friend

Yes, I use the DW Login Script as it works fine but if it uses the user_name as an identifier, How can i call it to get the user to the suitable page ?!

and what is meant by " If you want to replace that with the user_id then this is a simple tweak to the login script " didnt get it

thanks again,
Galal
__________________
Trying to learn anything b4 college
galileo is offline   Reply With Quote
Old 11-10-2006, 05:39 PM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

post your login code
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 11-10-2006, 05:41 PM   #5
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

also...

i am going to write a login script video tutorial over the weekend

it may help
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 11-10-2006, 08:45 PM   #6
galileo
 
Join Date: Nov 2006
Posts: 8
Default

Here is my Login Code ..

Code:
// *** 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['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "cp.php";
  $MM_redirectLoginFailed = "not-allowed2.html";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_connectnow, $connectnow);
  
  $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username='%s' AND password='%s'",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
   
  $LoginRS = mysql_query($LoginRS__query, $connectnow) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
btw, im waitin to see your video mate
__________________
Trying to learn anything b4 college
galileo is offline   Reply With Quote
Old 11-10-2006, 09:08 PM   #7
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

added code which will set your $_SESSION['user_id'].

you need to find $rowAccount['user_id']; and change the user_id to the name of the id in your db

Code:
// *** 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['username'])) { 
  $loginUsername=$_POST['username']; 
  $password=$_POST['password']; 
  $MM_fldUserAuthorization = ""; 
  $MM_redirectLoginSuccess = "cp.php"; 
  $MM_redirectLoginFailed = "not-allowed2.html"; 
  $MM_redirecttoReferrer = false; 
  mysql_select_db($database_connectnow, $connectnow); 
  
  $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username='%s' AND password='%s'", 
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
    
  $LoginRS = mysql_query($LoginRS__query, $connectnow) or die(mysql_error()); 
  $loginFoundUser = mysql_num_rows($LoginRS); 
  $rowAccount = @mysql_fetch_array($LoginRS); // *** << added to get back records ******
  
  if ($loginFoundUser) { 
     $loginStrGroup = ""; 
    
    //declare two session variables and assign them 
    $_SESSION['MM_Username'] = $loginUsername; 
    $_SESSION['MM_UserGroup'] = $loginStrGroup; 
    $_SESSION['user_id'] = $rowAccount['user_id']; // *** << added to set id in session *****

    if (isset($_SESSION['PrevUrl']) && false) { 
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
    } 
    header("Location: " . $MM_redirectLoginSuccess ); 
  } 
  else { 
    header("Location: ". $MM_redirectLoginFailed ); 
  } 
}
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 11-10-2006, 09:11 PM   #8
galileo
 
Join Date: Nov 2006
Posts: 8
Default

ok ,, thanks for your help .. However, and sorry for my many questions .. How can i get the id of the logged in user in a page and get all his info based on this id ?!

to get my point clearer :

I have a Control Panel page .. I will put a link as "Options" or "Preference" which will direct the user to "preference.php?id=[id of user]"

Yours,
Galal
__________________
Trying to learn anything b4 college
galileo is offline   Reply With Quote
Old 11-10-2006, 09:16 PM   #9
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

Code:
How can i get the id of the logged in user in a page and get all his info based on this id ?!
the code above will get and set a session of the id of the logged in user. Using this session you can get the user details any time using a SELECT when you need to
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 11-10-2006, 09:24 PM   #10
galileo
 
Join Date: Nov 2006
Posts: 8
Default

will try mate and will let you know .. thanks a lot (Y) *thumbs up*
__________________
Trying to learn anything b4 college
galileo is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:23 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com