Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

mysql_fetch_array($sql); Problems...

Recommended Posts

Hi Guys...
I've been setting a user system in sessions which is:
$user = $_POST['user'];
$_SESSION['LoggedIn'] = true;
$_SESSION['username'] = $user;

with all the other codes as well. Then I have my sessions code to check int he user is logged in by:
$LoggedIn = $_SESSION['LoggedIn'];
$usrname = $_SESSION['username'];

when I use codes like welcome $usrname I get this:
welcome Array.
Any ideas how I can get the username session to set the username and then retrieve this?

Share this post


Link to post
Share on other sites
if its saying array, then thats means you have to write something like

$usrname[0] or $usrname[1] instead usually ;)

Share this post


Link to post
Share on other sites
What do you get if you try ....

[code=php:0]
print_r($_SESSION['username']);
[/code]

?

Share this post


Link to post
Share on other sites
using print_r();

I get this:
Array ( [id] => 1 [user] => xyn [pass] => md5pass [name] => Ash [mail] => ash@eumod.co.uk [date] => 03.07.06 [time] => 11:42am [active] => 1 [news] => 1 [ban] => 0 [pm] => 1 [alert] => 1 )

Share this post


Link to post
Share on other sites
Yep. Its definately an array. $_SESSION['username']['user'] seems to hold your username, but I suspect this isn't what your looking for.

Post your code.

Share this post


Link to post
Share on other sites
Nope this has only worked when echoing:
welcome $username.

How would I make the array to place it into an SQL Query,
[code=php:0]include "db.php";
$result = mysql_query("SELECT * FROM pm WHERE sendto='$_SESSION['username']'");
while($data2 = @mysql_fetch_row($result)){
$stats = $data2[7];
if($stats=="0"){
$new="<img src='images/new.jpg'>";
}
}[/code]

Share this post


Link to post
Share on other sites
[code=php:0]
$result = mysql_query("SELECT * FROM pm WHERE sendto='{$_SESSION['username']['user']}");
[/code]

Share this post


Link to post
Share on other sites
Thanks, It worked i'll just check to see then i#ll report if any issues where to come up.

Share this post


Link to post
Share on other sites
I have one problem:
[code=php:0]$query = "UPDATE accounts SET mail='".strtolower($_POST['newemail'])."' WHERE user='".strtolower({$_SESSION['username']['user']})."'" or die(mysql_error());[/code]

I get:
Parse error: syntax error, unexpected '{', expecting ')' in ./Zone/Account/Reset_email.php on line 172

Line 172:
[code=php:0]$query = "UPDATE accounts SET mail='".strtolower($_POST['newemail'])."' WHERE user='".strtolower({$_SESSION['username']['user']})."'" or die(mysql_error());
[/code]

Share this post


Link to post
Share on other sites
Remove the curly braces in that line. They are not needed and are illegal in that context.

Ken

Share this post


Link to post
Share on other sites
Remove the curley braces from that 2nd strtolower() function. 

I only use curley braces when the variables is in a string.  Here it's in a function

Share this post


Link to post
Share on other sites

×

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.