PDA

View Full Version : Several Questions converning DW,PHP & MYSQL


galileo
11-09-2006, 01:25 PM
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 :cry: )

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 :oops:

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

Yours,
Galal

davidj
11-10-2006, 04:27 PM
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

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...

$text = nl2br($_POST['textarea']);

this will replace \n with

galileo
11-10-2006, 04:34 PM
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 :oops:

thanks again,
Galal

davidj
11-10-2006, 04:39 PM
post your login code

davidj
11-10-2006, 04:41 PM
also...

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

it may help

galileo
11-10-2006, 07:45 PM
Here is my Login 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 8)

davidj
11-10-2006, 08:08 PM
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

// *** 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 );
}
}

galileo
11-10-2006, 08:11 PM
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 ?! :roll:

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

davidj
11-10-2006, 08:16 PM
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

galileo
11-10-2006, 08:24 PM
will try mate and will let you know .. thanks a lot (Y) *thumbs up*

galileo
11-10-2006, 09:00 PM
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

Sorry, Didnt get that SELECT part .. how to make it using dreamweaver if it possible or otherwise? :oops:

davidj
11-11-2006, 09:36 AM
im sorry but if your looking for a button to do this or a checkbox in dreamweaver then your not going to be very happy

you have to hand code this as i have done

also in your signatue you have Trying to learn anything b4 college

my advice to you is learn PHP. Dont waste your time learning wizards.

galileo
11-13-2006, 01:32 PM
im sorry but if your looking for a button to do this or a checkbox in dreamweaver then your not going to be very happy

you have to hand code this as i have done

also in your signatue you have Trying to learn anything b4 college

my advice to you is learn PHP. Dont waste your time learning wizards.

well, thanks for your advice // i appreciate it .. however, since that i started to learn dreamweaver aiming to get the best out of it, therefore i will not stop learning it but ill start learning PHP besides it.

Also, I've found what i was looking for in dreamweaver about that SELECT part so as for now, i have no more questions :)

thanks for your help again,
Galal