logo-dw

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

Reply
 
Thread Tools Display Modes
Old 08-18-2011, 08:05 PM   #1
youthknight
 
Join Date: Aug 2011
Posts: 1
Default cannot retrieve data from recordset with mysql and dw cs4

Hi guys, im building a school site where parents are suppose to login to veiw their childrens poins, merits demerits etc.

aims:

1) user registration system - wich i accomplised through the login server behaviour

2) sucsessful logins should go to a profile page only seeing the info of their child - this is where i got stuck

im fairly new to php and databases, after many strugles i came to the solution of recalling the students data in the same way you recall the firstname of the user in a greatings message.

In detail:

In the "successful login" page I created a resticted server behaviour.

I created a record set to retrieve all the fields from the database i need (poins merits etc.)

with the filter: username, = , session variable, MM_Username to recal the username that was stored in the MM_Username session at login.

When i test this connection it askes for a test value on wich it successfully displays the record of the username i entered.

Then i proceed to the bindings tab and click and drag the recuired records where i desire in design veiw to create code like {get_user.Surname}.

this is as far as any manual could take me, after this it is supose to work but when i load it in a browser the spaces are just left blank!

since testing the recordset is successful im guessing the problem lies with the session MM_Username not storing the data?

Can anyone please tell me what im doing wrong, or even a beter suggestion on how to accomplish the profile page after login!

Perhaps the php code can help


PHP Code:
<?php require_once('Connections/tset.php'); ?>

<?php
if (!isset($_SESSION)) {
  
session_start();
}
$MM_authorizedUsers "";
$MM_donotCheckaccess "true";

 
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers$strGroups$UserName$UserGroup) {
  
// For security, start by assuming the visitor is NOT authorized.
  
$isValid False;

 
  
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
  // Therefore, we know that a user is NOT logged in if that Session variable is blank.
  
if (!empty($UserName)) {
    
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
    // Parse the strings into arrays.
    
$arrUsers Explode(","$strUsers);
    
$arrGroups Explode(","$strGroups);
    if (
in_array($UserName$arrUsers)) {
      
$isValid true;
    }
    
// Or, you may restrict access to only certain users based on their username.
    
if (in_array($UserGroup$arrGroups)) {
      
$isValid true;
    }
    if ((
$strUsers == "") && true) {
      
$isValid true;
    }
  }
  return 
$isValid;
}

 
$MM_restrictGoTo "loginfail.php";
if (!((isset(
$_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {  
  
$MM_qsChar "?";
  
$MM_referrer $_SERVER['PHP_SELF'];
  if (
strpos($MM_restrictGoTo"?")) $MM_qsChar "&";
  if (isset(
$QUERY_STRING) && strlen($QUERY_STRING) > 0)
  
$MM_referrer .= "?" $QUERY_STRING;
  
$MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
  
header("Location: "$MM_restrictGoTo);
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

 
  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 
  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;   
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

 
$colname_get_user "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_get_user $_SESSION['MM_Username'];
}
mysql_select_db($database_tset$tset);
$query_get_user sprintf("SELECT `First name`, Surname FROM `table 2` WHERE Username = %s"GetSQLValueString($colname_get_user"text"));
$get_user mysql_query($query_get_user$tset) or die(mysql_error());
$row_get_user mysql_fetch_assoc($get_user);
$colname_get_user "-1";
if (isset(
$_SESSION['MM_Usename'])) {
  
$colname_get_user $_SESSION['MM_Usename'];
}
mysql_select_db($database_tset$tset);
$query_get_user sprintf("SELECT `First name`, Surname, Maths, English, Bio, Science, Merits, Demerits, `Days missed` FROM `table 2` WHERE Username = %s"GetSQLValueString($colname_get_user"text"));
$get_user mysql_query($query_get_user$tset) or die(mysql_error());
$row_get_user mysql_fetch_assoc($get_user);
$totalRows_get_user mysql_num_rows($get_user);
?>
youthknight 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 10:13 AM.


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