Jump to content


Photo

mysql_fetch_array($sql); Problems...


  • Please log in to reply
11 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 05 July 2006 - 02:15 PM

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?

#2 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 July 2006 - 02:27 PM

if its saying array, then thats means you have to write something like

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

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 02:28 PM

What do you get if you try ....

print_r($_SESSION['username']);

?

#4 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 05 July 2006 - 02:32 PM

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 )

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 02:36 PM

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.

#6 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 05 July 2006 - 02:40 PM

Nope this has only worked when echoing:
welcome $username.

How would I make the array to place it into an SQL Query,
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'>";
 }
}


#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 02:42 PM

$result = mysql_query("SELECT * FROM pm WHERE sendto='{$_SESSION['username']['user']}");


#8 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 05 July 2006 - 02:44 PM

Thanks, It worked i'll just check to see then i#ll report if any issues where to come up.

#9 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 05 July 2006 - 02:52 PM

I have one problem:
$query = "UPDATE accounts SET mail='".strtolower($_POST['newemail'])."' WHERE user='".strtolower({$_SESSION['username']['user']})."'" or die(mysql_error());

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

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


#10 Birdman203

Birdman203
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 05 July 2006 - 02:54 PM

Delete the {} around $_SESSION['username']['user']

#11 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 July 2006 - 02:54 PM

Remove the curly braces in that line. They are not needed and are illegal in that context.

Ken

#12 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 05 July 2006 - 02:55 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users