Current location: Hot Scripts Forums » Programming Languages » PHP » Need help with SQL query


Need help with SQL query

Reply
  #1 (permalink)  
Old 10-30-09, 09:13 PM
sac0o01 sac0o01 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Need help with SQL query

I have been working on a script that creates a directory named after the logged in username and then the user will be able to upload to that directory.

I am using the following to try and get the username so that I might insert it into the upload script path.


PHP Code:

<?php

session_start
();
include_once(
"dbc.php");
   if(isset(
$_SESSION['userSession']) && !empty($_SESSION['userSession']))
 
        include_once(
"dbc.php");
$username mysql_query("SELECT * FROM users WHERE username =".$_SESSION['userId']); 
?>
When I run it I get the following:
Error: The directory (/home2/freefor3/public_html/ rotas/sigs/Resource id #4) doesn't exist

Now I understand why it is printing out "Resource id #4" My question is what can I do to get it to return the username itself?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-30-09, 10:00 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
What is the user ID, is it the auto increment column?

PHP Code:

<?php
session_start
();
include_once(
"dbc.php");
   if(isset(
$_SESSION['userSession']) && !empty($_SESSION['userSession']))
 
        include_once(
"dbc.php");
$result mysql_query("SELECT name FROM users WHERE username ='".$_SESSION['userId'] . "'"); 
$row mysql_fetch_row($result);
$username $row[0];
?>
Change the query (name) to reflect exactly what column your looking for. I'm assuming 'userid' is the integer of the row.

PS. you could always just save the username into a $_SESSION variable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to Jcbones For This Useful Post:
sac0o01 (10-31-09)
  #3 (permalink)  
Old 10-31-09, 10:39 AM
sac0o01 sac0o01 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Perfect! Thanks, I have been messing with this for hours. I had tried that approach before and it didn't work. It was your advice on the column that helped the most. I guess I need to study a little bit on database queries.

Thanks a million.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Query based on last 48 hours? philmckrackon PHP 1 05-07-08 07:56 AM
dynamic where section of sql query soloWebDev Script Requests 3 01-31-08 03:48 PM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM
change my field in this example sal21 ASP 3 07-14-03 03:49 AM


All times are GMT -5. The time now is 01:24 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.