affordit Posted August 23, 2009 Share Posted August 23, 2009 I am trying redirect users to another page if a query has already been run, this is what I got if (mysql_query($query2)){ $done="done"; } This is not setting a value to $done what am I doing wrong here. Thanks Quote Link to comment Share on other sites More sharing options...
oni-kun Posted August 23, 2009 Share Posted August 23, 2009 The IF has its own scope and can't touch any variables outside, unless you're using globals (safe type). You can do these.. if (mysql_query($query2)){ echo "done"; //Just echo it where needed. } if (mysql_query($query2)){ $GLOBALS['done'] = "done"; //Set global $done as 'done', as you wanted } Quote Link to comment Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 Errrr.... That's just wrong oni-kun. if() Inherits what ever scope it's in, but does not create it's own scope. For example: $x = 5; if($x == 5) { $x = 6; } echo $x; Would say "6". Chances are, if done is not getting a value, it's either being unset somewhere else or the query is failing. Quote Link to comment Share on other sites More sharing options...
affordit Posted August 23, 2009 Author Share Posted August 23, 2009 The query works it inserts into db but when the query runs it wont redirect $done is not getting a value Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.