$variable vs. number

hi I’m having trouble with transferring numbers from variables. Numbers work but a variable doesn’t…

With Variable

$id = $logOptions_id; 
$sql = mysql_query("SELECT * FROM myMembers WHERE id=$id"); 
while($row = mysql_fetch_array($sql)){
	$idUser = $row["id"]; 
	$secure_id = $row["secure_id"]; 
};
print "members/$idUser/mp3_files/$secure_id/";
// Place file on server, into the images folder
move_uploaded_file($_FILES['Filedata']['tmp_name'], "members/$idUser/mp3_files/$secure_id/".$filename);

With Number

$id = 1;
$sql = mysql_query("SELECT * FROM myMembers WHERE id=$id"); 
while($row = mysql_fetch_array($sql)){
	$idUser = $row["id"]; 
	$secure_id = $row["secure_id"]; 
};
print "members/$idUser/mp3_files/$secure_id/";
// Place file on server, into the images folder
move_uploaded_file($_FILES['Filedata']['tmp_name'], "members/$idUser/mp3_files/$secure_id/".$filename);

How can I make a variable work to replace them to a number?
Thanks in advance.

Have you made sure the $logOptions_id variable is initiated with a value?

yes I have set $logOptions_id to a cookie here
$logOptions_id = $_COOKIE[‘idCookie’];
which right now the content is 1.

does the variable have to be in a certain format number? ex (int) (short)

If it contained 1 then it would process exactly the same as the second example you said did work so obviously it doesn’t contain 1. Try echoing it to see what it actually does contain.

To prevent it from crashing when it doesn’t contain a number, try this:


$id = (int) $logOptions_id;  
$sql = mysql_query("SELECT * FROM myMembers WHERE id='{$id}'");

it seems to stop when it gets to move_uploaded_file
because it prints out just fine

members/1/mp3_files/1874639102

but the mp3 doesn’t upload to the folder.
i’m guessing it’s the move_uploaded_file that’s causing it to stop.

You probably have to chown write permissions on that folder…

chown -R www-data members (for Ubuntu)
cnown -R apache members (for RedHat)

Then:

chmod -R 755 members

I don’t understand but I have this set on the registration page

     mkdir("members/$id", 0755);
     mkdir("members/$id/mp3_files", 0755);
     mkdir("members/$id/mp3_files/$secureID", 0755);

everything works fine with a number.