tags:

views:

50

answers:

3

hey i guys i want help from you. i am working on website project, in that i want to create "if user upload some data then it will be stored in his folder" for this i want currently login username.Because the folder name=username. when user register to my website it will create folder in webspace which name=username. now i want to take currently login username for defining path to uploaded image. i give you example:

if (isset($_SESSION['username']))
{
    $username=($_SESSION['username']);
    $CHECK=mysql_query("Select `status` from `user_reg` where `username`=$username");

    if ($check="Admin") {
    $userimage="/Place4Info/Data/Admin_data/".$username."/";

} else {
    $userimage="/Place4Info/Data/User_data/".$username."/";

}

i save path in $userimage & then use it everywhere. above code is not running

A: 

you need to use mysql_fetch_array on the result of your query:

$res = mysql_query("Selectstatusfromuser_regwhereusername=$username");
$check = mysql_fetch_array($res);

Also I noticed you are switching between UPPERCASE check and lowercase, you can't mix them up in PHP.

Andrei Serdeliuc
+2  A: 

Use double =:

if ($check == "Admin") {
   $userimage="/Place4Info/Data/Admin_data/".$username."/";
Lekensteyn
+2  A: 

First, $CHECK is not the same as $check. Second, $CHECK is a mysql resource, not a string containing a value from the database. Third, you can print mysql_error() after mysql_query() to determine wheter the query failed and why.

Something like:

if (isset($_SESSION['username'])) { 
  $username = $_SESSION['username']; 
  $res = mysql_query("Select status from user_reg where username='$username'");
  $row = mysql_fetch_assoc($res);
  $check = $row['status'];

  if ($check == "Admin") { 
    $userimage = "/Place4Info/Data/Admin_data/".$username."/";
  } 
  else { 
    $userimage = "/Place4Info/Data/User_data/".$username."/";
  }
}
Johan
$check = ... is still an affectation :-)
Aif
@alf: Thanks. Fixed. :)
Johan