Jump to content

Can't show mm_username variable


garydt

Recommended Posts

Hi. I hope someone can help as I've been struggling with this for a few weeks.

On the first php page I have the user register and log in automatically. On the 2nd php page i want to greet the username but the MM_Username variable won't appear on the screen. I'm using Apache2 as the testing server with Dreamweaver 8.02. Where am I going wrong?

 

Here's the code:-

 

<?php require_once('Connections/registration.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

$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;

}

}

 

// *** Redirect if username exists

$MM_flag="MM_insert";

if (isset($_POST[$MM_flag])) {

$MM_dupKeyRedirect="usernam.html";

$loginUsername = $_POST['username'];

$LoginRS__query = sprintf("SELECT username FROM tablename1 WHERE username=%s", GetSQLValueString($loginUsername, "text"));

mysql_select_db($database_registration, $registration);

$LoginRS=mysql_query($LoginRS__query, $registration) or die(mysql_error());

$loginFoundUser = mysql_num_rows($LoginRS);

 

//if there is a row in the database, the username was found - can not add the requested username

if($loginFoundUser){

$MM_qsChar = "?";

//append the username to the redirect page

if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";

$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;

header ("Location: $MM_dupKeyRedirect");

exit;

}

}

 

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

$insertSQL = sprintf("INSERT INTO tablename1 (fname, surname, sex, country, email, username) VALUES (%s, %s, %s, %s, %s, %s)",

GetSQLValueString($_POST['fname'], "text"),

GetSQLValueString($_POST['surname'], "text"),

GetSQLValueString(isset($_POST['sex']) ? "true" : "", "defined","1","0"),

GetSQLValueString($_POST['country'], "text"),

GetSQLValueString($_POST['email'], "text"),

GetSQLValueString($_POST['username'], "text"));

 

mysql_select_db($database_registration, $registration);

$Result1 = mysql_query($insertSQL, $registration) or die(mysql_error());

 

$insertGoTo = "recordin.php";

if (isset($_SERVER['QUERY_STRING'])) {

$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

$insertGoTo .= $_SERVER['QUERY_STRING'];

}

header(sprintf("Location: %s", $insertGoTo));

}

?><?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['email'];

$MM_fldUserAuthorization = "";

$MM_redirectLoginSuccess = "recordin.php";

$MM_redirectLoginFailed = "usernam.html";

$MM_redirecttoReferrer = false;

mysql_select_db($database_registration, $registration);

 

$LoginRS__query=sprintf("SELECT username, email FROM tablename1 WHERE username=%s AND email=%s",

GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

 

$LoginRS = mysql_query($LoginRS__query, $registration) or die(mysql_error());

$loginFoundUser = mysql_num_rows($LoginRS);

if ($loginFoundUser) {

$loginStrGroup = "";

 

//declare two session variables and assign them

$GLOBALS['MM_Username'] = $loginUsername;

$GLOBALS['MM_UserGroup'] = $loginStrGroup;

 

if (isset($_SESSION['PrevUrl']) && false) {

$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];

}

header("Location: " . $MM_redirectLoginSuccess );

}

else {

header("Location: ". $MM_redirectLoginFailed );

}

}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<script type="text/JavaScript">

<!--

function MM_findObj(n, d) { //v4.01

var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];

for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);

if(!x && d.getElementById) x=d.getElementById(n); return x;

}

 

function MM_validateForm() { //v4.0

var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);

if (val) { nm=val.name; if ((val=val.value)!="") {

if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';

} else if (test!='R') { num = parseFloat(val);

if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';

if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

min=test.substring(8,p); max=test.substring(p+1);

if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }

} if (errors) alert('The following error(s) occurred:\n'+errors);

document.MM_returnValue = (errors == '');

}

//-->

</script>

</head>

 

<body>

<div align="center">

<form action="<?php echo $loginFormAction; ?>" method="POST" name="form1" id="form1" onsubmit="MM_validateForm('fname','','R','surname','','R','email','','RisEmail','username','','R');return document.MM_returnValue">

<table width="500" border="0">

<tr>

<td><label>First name

<input name="fname" type="text" id="fname" />

</label></td>

<td><label>Surname

<input name="surname" type="text" id="surname" />

</label></td>

</tr>

<tr>

<td>Sex:

<label> M

<input name="sex" type="radio" value="radiobutton" />

F

<input name="radiobutton" type="radio" value="radiobutton" />

</label></td>

<td><label>Country

<select name="country" size="1" id="country">

<option>Austrailia</option>

<option>Japan</option>

<option>United Kingdom</option>

<option>United States</option>

</select>

</label></td>

</tr>

<tr>

<td><label>Email address

<input name="email" type="text" id="email" />

</label></td>

<td><label>Username

<input name="username" type="text" id="username" />

</label></td>

</tr>

<tr>

<td colspan="2"><div align="center">

<label>

<input type="submit" name="Submit" value="Submit" />

</label>

</div></td>

</tr>

</table>

<input type="hidden" name="MM_insert" value="form1" />

</form>

</div>

</body>

</html>

 

---------

 

2nd page:-

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

Hello <?php echo $_SESSION['MM_Username']; ?>

</body>

</html>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.