melting_dog Posted July 17, 2010 Share Posted July 17, 2010 Hi all, I have a page that runs a query where users can send info via either a form (post) or from redirecting from another page (get). The get function uses: header("location:forumsDiscussion.php?$comDiscussNo"); to send content of the $comDiscussNo variable and appears to work fine: i can see the variable content in the URL. but when i put these into if statements it doesnt run. Heres the code: <?php $discussIDtrans = $_GET['$comDiscussNo']; if ($discussIDtrans = null) { $discussID=(int)$_POST['discussID']; } else { $discussID = $discussIDtrans; } $sql = "SELECT * FROM discussion WHERE discussID ='$discussID'"; ******ETC ETC ETC******* Anyone have any ideas why this isnt working? Cheers Link to comment https://forums.phpfreaks.com/topic/208006-opening-page-with-get-and-post/ Share on other sites More sharing options...
kenrbnsn Posted July 17, 2010 Share Posted July 17, 2010 Your "if" statement is incorrect. Use one "=" for assignment, two "==" for comparison. Ken Link to comment https://forums.phpfreaks.com/topic/208006-opening-page-with-get-and-post/#findComment-1087345 Share on other sites More sharing options...
robert_gsfame Posted July 17, 2010 Share Posted July 17, 2010 again this part look suspicious $discussID=(int)$_POST['discussID']; you are using header() so use $_GET instead of $_POST Link to comment https://forums.phpfreaks.com/topic/208006-opening-page-with-get-and-post/#findComment-1087350 Share on other sites More sharing options...
robert_gsfame Posted July 17, 2010 Share Posted July 17, 2010 I am not sure what is $comDiscussNo but i only guess that it is comDiscussNo=blablabla header("location:forumsDiscussion.php?$comDiscussNo"); $_GET['$comDiscussNo']; so bold part also wrong should be $_GET['comDiscussNo']; Link to comment https://forums.phpfreaks.com/topic/208006-opening-page-with-get-and-post/#findComment-1087352 Share on other sites More sharing options...
melting_dog Posted July 17, 2010 Author Share Posted July 17, 2010 Thanks guys. i fixed the if statement and using an alert box narrowed the problem down to the get: although the correct variable content is shown in the URL it is not reaching the page: $_GET['comDiscussNo']; has nothing in it (even after changing it like robert suggested). Anyone got any other ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/208006-opening-page-with-get-and-post/#findComment-1087354 Share on other sites More sharing options...
melting_dog Posted July 17, 2010 Author Share Posted July 17, 2010 Thanks guys. i fixed the if statement and using an alert box narrowed the problem down to the get: although the correct variable content is shown in the URL it is not reaching the page: $_GET['comDiscussNo']; has nothing in it (even after changing it like robert suggested). Anyone got any other ideas? Thanks ...but this is also strange because even if $_GET['comDiscussNo']; has nothing in it the if statement: $discussIDtrans = $_GET['comDiscussNo']; $discussIDpost =(int)$_POST['discussID']; if ($discussIDtrans == null) { $discussID = $discussIDpost; } else { $discussID = $discussIDtrans; } should just pass it on to the else statement, making $discussID equal to the POST weird... Link to comment https://forums.phpfreaks.com/topic/208006-opening-page-with-get-and-post/#findComment-1087357 Share on other sites More sharing options...
robert_gsfame Posted July 17, 2010 Share Posted July 17, 2010 try change this: if ($discussIDtrans == null) with this if(empty($discussIDtrans)){ Link to comment https://forums.phpfreaks.com/topic/208006-opening-page-with-get-and-post/#findComment-1087362 Share on other sites More sharing options...
melting_dog Posted July 17, 2010 Author Share Posted July 17, 2010 try change this: if ($discussIDtrans == null) with this if(empty($discussIDtrans)){ Thanks heaps Robert, that has fixed the problem of $_GET['comDiscussNo']; being null. But any suggestions on why the $_GET isnt working? Cheers again! Link to comment https://forums.phpfreaks.com/topic/208006-opening-page-with-get-and-post/#findComment-1087365 Share on other sites More sharing options...
robert_gsfame Posted July 17, 2010 Share Posted July 17, 2010 I only use null when it comes to query not for if statement Link to comment https://forums.phpfreaks.com/topic/208006-opening-page-with-get-and-post/#findComment-1087367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.