SauloA Posted January 23, 2007 Share Posted January 23, 2007 I am new to PHP and have been using Dreamweaver to develop my blog. When a user logs into the website I want there "user_id" to be stored but Dreamweaver's Log In User Server Behavior doesn't store a session variable for the "user_id". I tried modifying the code slightly to add a MM_UserID session variable but the "user_id" isn't being stored, I think. When a user adds a comment the "user_id" is supposed to be filled into the form with the MM_UserID session variable into the hidden field.Here's my code below. The red text is what I added into the code. I'd appreciate the help since this problem has been bugging me for 1 week.[font=Verdana]<?php require_once('../Connections/connBlog.php'); ?><?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['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = "al_levelid"; $MM_redirectLoginSuccess = "home.php"; $MM_redirectLoginFailed = "failed.php"; $MM_redirecttoReferrer = true; mysql_select_db($database_connBlog, $connBlog); $LoginRS__query=sprintf("SELECT [color=red]user_id[/color], user_sname, user_pass, al_levelid FROM user_tbl WHERE user_sname='%s' AND user_pass='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $connBlog) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'al_levelid'); //declare three session variables and assign them $_SESSION['MM_Username'] = $loginUsername; [color=red]$_SESSION['MM_UserID'] = $loginFoundUser['user_id'];[/color] $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); }}?>[/font] Quote Link to comment Share on other sites More sharing options...
Caesar Posted January 23, 2007 Share Posted January 23, 2007 Dude....don't even use Dreamweaver as a means of starting. If you're a beginner....run through a few online tutorials and learn to handcode. Dreamweaver is the absolute worst way to learn. Quote Link to comment Share on other sites More sharing options...
SauloA Posted January 24, 2007 Author Share Posted January 24, 2007 Although Dreamweaver may have been a bad approach to create my website, is there still a way to fix my situation? Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted January 24, 2007 Share Posted January 24, 2007 If you want to take a value from a query, you'll need to turn it into an array with mysql_fetch_array(). I've edited the code below, although it's untested so it might need something else. Also, when posting your code, stick it in [ CODE ] tags.[code]<?php require_once('../Connections/connBlog.php'); ?><?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['username'])) { $loginUsername=$_POST['username']; $password=$_POST['password']; $MM_fldUserAuthorization = "al_levelid"; $MM_redirectLoginSuccess = "home.php"; $MM_redirectLoginFailed = "failed.php"; $MM_redirecttoReferrer = true; mysql_select_db($database_connBlog, $connBlog); $LoginRS__query=sprintf("SELECT user_id, user_sname, user_pass, al_levelid FROM user_tbl WHERE user_sname='%s' AND user_pass='%s'", get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); $LoginRS = mysql_query($LoginRS__query, $connBlog) or die(mysql_error()); $LoginArray= mysql_fetch_array($LoginRS); //Creates the array $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { $loginStrGroup = mysql_result($LoginRS,0,'al_levelid'); //declare three session variables and assign them $_SESSION['MM_Username'] = $loginUsername; $_SESSION['MM_UserID'] = $LoginArray['user_id']; //Stores the user_id in a session variable. $_SESSION['MM_UserGroup'] = $loginStrGroup; if (isset($_SESSION['PrevUrl']) && true) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; } header("Location: " . $MM_redirectLoginSuccess ); } else { header("Location: ". $MM_redirectLoginFailed ); }}?>[/code] Quote Link to comment Share on other sites More sharing options...
SauloA Posted January 24, 2007 Author Share Posted January 24, 2007 The code works. Thanks a bunch CageCrawler. ;D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.