nander Posted November 30, 2011 Share Posted November 30, 2011 Hello I am creating a simple Discussion Forum, and I cant get past my IF Statement to verify topics exist? Please help? <?php //check for required info from the query string if (!$_GET[topic_id]) { header("Location: topiclist.php"); exit; } //connect to server and select database $link = mysql_connect('votpservicescom.ipagemysql.com', 'mantest', 'testman') or die(mysql_error()); mysql_select_db("learn2db",$link) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/252145-cant-get-past-if-statement-to-connect-to-database/ Share on other sites More sharing options...
jotorres1 Posted November 30, 2011 Share Posted November 30, 2011 Try: <?php //check for required info from the query string if (!isset($_GET[topic_id])) { header("Location: topiclist.php"); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/252145-cant-get-past-if-statement-to-connect-to-database/#findComment-1292724 Share on other sites More sharing options...
Psycho Posted November 30, 2011 Share Posted November 30, 2011 You should also put quotes around the array index. if (!isset($_GET['topic_id'])) { If you are still not getting past that if() statement, then put this before the if statement for debugging purposes to see what, if any, values are present in the global $_GET array echo "Get Vars:<pre>" . print_r($_GET) . "</pre>"; exit(); Quote Link to comment https://forums.phpfreaks.com/topic/252145-cant-get-past-if-statement-to-connect-to-database/#findComment-1292727 Share on other sites More sharing options...
jotorres1 Posted November 30, 2011 Share Posted November 30, 2011 Wow, I didn't catch that either, you need the quotes 'topic_id' in order to get the value from url. Nice find mjdamato Quote Link to comment https://forums.phpfreaks.com/topic/252145-cant-get-past-if-statement-to-connect-to-database/#findComment-1292730 Share on other sites More sharing options...
nander Posted November 30, 2011 Author Share Posted November 30, 2011 mjdamato I got this on the output Array ( ) Get Vars: 1 Quote Link to comment https://forums.phpfreaks.com/topic/252145-cant-get-past-if-statement-to-connect-to-database/#findComment-1292786 Share on other sites More sharing options...
Psycho Posted December 1, 2011 Share Posted December 1, 2011 Oh, sorry, forgot the 2nd parameter for print_r(). Use this: echo "Get Vars:<pre>" . print_r($_GET, true) . "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/252145-cant-get-past-if-statement-to-connect-to-database/#findComment-1292841 Share on other sites More sharing options...
nander Posted December 1, 2011 Author Share Posted December 1, 2011 Ok here is what I get now? Get Vars: Array ( ) Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb25b/b904/ipg.votpservicescom/showtopic.php:3) in /hermes/bosweb25b/b904/ipg.votpservicescom/showtopic.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/252145-cant-get-past-if-statement-to-connect-to-database/#findComment-1292857 Share on other sites More sharing options...
Psycho Posted December 1, 2011 Share Posted December 1, 2011 You have no values being passed in the $_GET array. Therefore the condition in you if() statement is resulting in true which causes the page to redirect. Quote Link to comment https://forums.phpfreaks.com/topic/252145-cant-get-past-if-statement-to-connect-to-database/#findComment-1292880 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.