ashrafzia Posted October 22, 2007 Share Posted October 22, 2007 I want the value of the variable $user to go inside the if statement inside the query, but its not working. How can i make the value of the variable $user as a global for access inside if....else block statements. $val = $_GET['id']; $user = $_GET['user']; if ($val == "AddPaper" && !isset($_POST['next_x'])){ //echo "$user"; $sql="SELECT programe_name FROM teachers WHERE teacher_name='$user' "; $result = mysql_query($sql, $conn) or die ("Can't Process Query".mysql_query()); while ($row=mysql_fetch_array($result)){ $add1 .= "<option value='$row[programe_name]'>$row[programe_name]</option>"; } I have a dropdown menu which has a link as http://localhost/xampp/......../myfile?id=AddPaper when i click the button the above if statement is executed but the value of the variable $user isn't coming inside it and before the button click i have a value inside the link as http://localhost/xampp.......myfile?user=$_post[name]. I hope you get what i want to say. Quote Link to comment https://forums.phpfreaks.com/topic/74313-variable-scope-problem/ Share on other sites More sharing options...
Perad Posted October 22, 2007 Share Posted October 22, 2007 $user = $_GET['user']; is $_GET['user'] defined in the URL? i.e.. page.php?user=Fred Quote Link to comment https://forums.phpfreaks.com/topic/74313-variable-scope-problem/#findComment-375469 Share on other sites More sharing options...
GingerRobot Posted October 22, 2007 Share Posted October 22, 2007 Well for starters, you will probably be getting an error because of this line: $result = mysql_query($sql, $conn) or die ("Can't Process Query".mysql_query()); It should be: $result = mysql_query($sql, $conn) or die ("Can't Process Query".mysql_error()); And im a little confused by your question. Are both $id and $name defined when you attempt this query? Im unsure as to what the drop down box has to do with this all. Quote Link to comment https://forums.phpfreaks.com/topic/74313-variable-scope-problem/#findComment-375483 Share on other sites More sharing options...
ashrafzia Posted October 22, 2007 Author Share Posted October 22, 2007 $user = $_GET['user']; is $_GET['user'] defined in the URL? i.e.. page.php?user=Fred Yes it is defined. I have an authentication script and after authenticating a person i am redirecting him to another page through header function and passing his name like this: header("Location: http://localhost/xampp/mypic/pictures.php?user=$_POST[name] "); Then i am getting his name like this: $user = $_GET['user']; Its working fine uptil here. Now when the if....else block statement appears it is hush. I don't know why? Quote Link to comment https://forums.phpfreaks.com/topic/74313-variable-scope-problem/#findComment-375591 Share on other sites More sharing options...
ashrafzia Posted October 22, 2007 Author Share Posted October 22, 2007 Well for starters, you will probably be getting an error because of this line: $result = mysql_query($sql, $conn) or die ("Can't Process Query".mysql_error()); And im a little confused by your question. Are both $id and $name defined when you attempt this query? Im unsure as to what the drop down box has to do with this all. Nice mistake pointed out. I didn't realized. Yes, both of them are defined. Quote Link to comment https://forums.phpfreaks.com/topic/74313-variable-scope-problem/#findComment-375593 Share on other sites More sharing options...
GingerRobot Posted October 22, 2007 Share Posted October 22, 2007 Well, if you are transferring with this header: header("Location: http://localhost/xampp/mypic/pictures.php?user=$_POST[name] "); Then they are not both defined. $id would not be defined, so the if statement would evaluate to false. You would need to do somthing like: header("Location: http://localhost/xampp/mypic/pictures.php?user=$_POST[name]&id=somevalue"); Quote Link to comment https://forums.phpfreaks.com/topic/74313-variable-scope-problem/#findComment-375596 Share on other sites More sharing options...
ashrafzia Posted October 22, 2007 Author Share Posted October 22, 2007 Well, if you are transferring with this header: header("Location: http://localhost/xampp/mypic/pictures.php?user=$_POST[name] "); Then they are not both defined. $id would not be defined, so the if statement would evaluate to false. You would need to do somthing like: header("Location: http://localhost/xampp/mypic/pictures.php?user=$_POST[name]&id=somevalue"); Still not working.... Quote Link to comment https://forums.phpfreaks.com/topic/74313-variable-scope-problem/#findComment-375631 Share on other sites More sharing options...
only one Posted October 22, 2007 Share Posted October 22, 2007 If you are using a forum to submit the data set the method to 'get' rather than 'post' Quote Link to comment https://forums.phpfreaks.com/topic/74313-variable-scope-problem/#findComment-375635 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.