$topic_id = $_GET['tid']; $ex_id = $_GET['ex_id']; //instead of repeating code //if get is null then use info from posted data if ($_GET['tid'] == NULL && $_GET['ex_id']== NULL){ $topic_id = $_POST['topic_id']; $ex_id = $_POST['ex_id']; $topic_query = "select * from topics where id=$topic_id"; $topic_result = mysql_query($topic_query) or die(mysql_error()); $topic_row = mysql_fetch_array($topic_result); //posts $post_query = "select * from posts where id=$ex_id"; $post_result = mysql_query($post_query) or die(mysql_error()); $post_row = mysql_fetch_array($post_result); }