first off thanks for being here for people that need help..8)
now on to the question..
not sure how to explain it. i am trying to follow some code examples from a couple of books. and for the most part they are working like the book says. the problem i am running into is trying to make results from a sql query globally avil. ie being able to shove a username into $username and use that on other pages. i know it can be put into $SESSION['username'] but i dont want to overload the $SESSION.
have tried searching the web for days and i guess my google skills suck about as bad as my coding skills..8(
below is the code page i am trying to work with:
<?php
session_start();
include("dbcon.func.php");
switch (@$_POST['Button'])
{
case "Login":
$cxn = Connect_to_db();
$sql = "SELECT username FROM users WHERE username='$_POST[username]'";
$result = mysqli_query( $cxn , $sql) or die ("could not execute query");
$num = mysqli_num_rows($result);
if($num == 1)
{
$sql = "SELECT * FROM users WHERE username='$_POST[username]' AND user_password=md5('$_POST[password]')";
$result2 = mysqli_query($cxn,$sql) or die ("could not execute query");
$row = mysqli_num_rows($result2);
if($row == 1)
{
$row2 = mysqli_fetch_array($result2, MYSQLI_BOTH);
$_SESSION['username']=$_POST['username'];
$_SESSION['auth']="yes";
header("Location: home.php");
}
elseif ($row == 0)
{
echo "Password not correct!!<br /><a href=javascript:history.back(-1)>Go back</a><br />";
}
}
elseif ($num == 0) //login name not found
{
echo "user name not found<br /><br /><a href=javascript:history.back(-1)>Go back</a><br />";
}
break;
default:
echo <<<EOC
<form method=post action=$_SERVER[PHP_SELF]>
<table border=2 align=center>
<tr><td>Username</td><td><input type=text name=username size=20 ></td></tr>
<tr><td>Password</td><td><input type=password name=password size=20></td></tr>
<tr><td colspan=2 align=center><input type=submit name=Button value=Login><input type=reset name=reset value=reset></td></tr>
</table>
</form>
EOC;
}
?>
the section where is sets the $_SESSION['username'] is where i am trying to work with. there are other fields in the users table that i would like to be able to assign to variables and use on other pages. how would i go about this?
have tried:
$GLOBALS[username] = $row2['username']
global $username
$username = $row2['username']
and none of these will output the username when called from the home.php page(called in the header redirect)
echo "welcome home". $GLOBALS['username'] . $row2['username'] . $username . $_SESSION['username'];
the only one that returns anything is the one set in the session.