kac001 Posted November 23, 2010 Share Posted November 23, 2010 Okay... so I am loading some content into my page from the database... I know how to do this normally... but here is the sticking point... I want to load the content from one of 5 options (so there are multiple pages with 5 different options for body copy) depending on what the value of the cookie is... Here is what I tried, but it did not work: //Determin which page ID to use in our query ---------------------------------------------------------------------------------------------- if (!$_GET['pid']){ $pageid = '1'; } else { $pageid = $_GET['pid']; } //Query the Main Content and Titles for the proper page --------------------------------------------------------------------------------------------- $sqlCommand="SELECT process_mainContent_vers1, process_mainContent_vers2, process_mainContent_vers3, process_mainContent_vers4, process_mainContent_vers5, process_pagetitle FROM pages_process WHERE process_id='$pageid' LIMIT 1"; $query=mysqli_query($myConnection, $sqlCommand) or die (mysql_error()); $body = ''; $title = ''; while ($row = mysqli_fetch_array($query)) { if (isset($_COOKIE['career_status'])) { $carreerStatus = ($_COOKIE['career_status']); if ($carreerStatus=="Starting Residency/Graduating Medical School") $body = $row["process_mainContent_vers1"]; if ($carreerStatus=="Ending Residency/Starting Fellowship") $body = $row["process_mainContent_vers2"]; if ($carreerStatus=="Practicing Physician") $body = $row["process_mainContent_vers3"]; if ($carreerStatus=="Practicing Physician") $body = $row["process_mainContent_vers4"]; if ($carreerStatus=="Hospital/Practice Administrator") $body = $row["process_mainContent_vers5"]; } else { $carreerStatus = ($_SESSION['career_status']); if ($carreerStatus=="Starting Residency/Graduating Medical School") $body = $row["process_mainContent_vers1"]; if ($carreerStatus=="Ending Residency/Starting Fellowship") $body = $row["process_mainContent_vers2"]; if ($carreerStatus=="Practicing Physician") $body = $row["process_mainContent_vers3"]; if ($carreerStatus=="Practicing Physician") $body = $row["process_mainContent_vers4"]; if ($carreerStatus=="Hospital/Practice Administrator") $body = $row["process_mainContent_vers5"]; } $title = $row["process_pagetitle"]; } mysqli_free_result($query); //----------------------------------------------------------------------------------------------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/219570-please-help-me-oh-yee-magical-programming-masters/ Share on other sites More sharing options...
dadamssg Posted November 23, 2010 Share Posted November 23, 2010 i would change the very first part to this...for sql injection reasons if (!$_GET['pid']){ $pageid = '1'; } else{ $pageid = (int) $_GET['pid']; if($pageid == 0) { $pageid = "1"; } } So if they do write letters/words in that parameter this would convert it to 0 and then set it to 1 Quote Link to comment https://forums.phpfreaks.com/topic/219570-please-help-me-oh-yee-magical-programming-masters/#findComment-1138384 Share on other sites More sharing options...
kac001 Posted November 23, 2010 Author Share Posted November 23, 2010 i would change the very first part to this...for sql injection reasons if (!$_GET['pid']){ $pageid = '1'; } else{ $pageid = (int) $_GET['pid']; if($pageid == 0) { $pageid = "1"; } } So if they do write letters/words in that parameter this would convert it to 0 and then set it to 1 okay... good idea and all, but what does that do as far as resolving my actual problem? Thanks anyway I just hope another person actually addresses what I am trying to do... Quote Link to comment https://forums.phpfreaks.com/topic/219570-please-help-me-oh-yee-magical-programming-masters/#findComment-1138393 Share on other sites More sharing options...
litebearer Posted November 23, 2010 Share Posted November 23, 2010 1. have you echo'd the $pageid to make sure it contains the value you ecpect 2. have you echo'd the $carreerStatus to make sure it contains the value you expect Quote Link to comment https://forums.phpfreaks.com/topic/219570-please-help-me-oh-yee-magical-programming-masters/#findComment-1138436 Share on other sites More sharing options...
Pikachu2000 Posted November 23, 2010 Share Posted November 23, 2010 You should start by seeing if the cookie or session vars actually hold the data you're trying to use in the conditionals (might consider making those into switch statements instead, too). Add this code at the head of the script and see what data you actually have coming in. echo '<pre>'; echo 'Cookie Data:'; print_r($_COOKIE); echo 'Session Data:'; print_r($SESSION); echo '</pre>' Quote Link to comment https://forums.phpfreaks.com/topic/219570-please-help-me-oh-yee-magical-programming-masters/#findComment-1138437 Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 question, re this thread. i usually use intval() to ensure submitted values are integers when required. is it better/faster/less resource-intensive to use (int) instead? $pageid = intval($_GET['pid']); // What I usually do. $pageid = (int) $_GET['pid']; // Is this better? Quote Link to comment https://forums.phpfreaks.com/topic/219570-please-help-me-oh-yee-magical-programming-masters/#findComment-1138456 Share on other sites More sharing options...
Pikachu2000 Posted November 23, 2010 Share Posted November 23, 2010 The problem with intval() against a form value is that all form values are, by default, strings. So it's kind of a crap shoot to assign the intval() of a string to a variable that needs to be an integer without validating it. I don't know if there's an advantage in processing overhead, or if it's technically right or wrong, but I normally do this for a value that's expected to be an integer. if( !empty($_POST['int_field']) && ctype_digit($_POST['int_field']) ) { $int_var = (int) $_POST['int_field']; } Quote Link to comment https://forums.phpfreaks.com/topic/219570-please-help-me-oh-yee-magical-programming-masters/#findComment-1138466 Share on other sites More sharing options...
Pikachu2000 Posted November 23, 2010 Share Posted November 23, 2010 You should start by seeing if the cookie or session vars actually hold the data you're trying to use in the conditionals (might consider making those into switch statements instead, too). Add this code at the head of the script and see what data you actually have coming in. echo '<pre>'; echo 'Cookie Data:'; print_r($_COOKIE); echo 'Session Data:'; print_r($SESSION); echo '</pre>' I just noticed I have a typo in there. $SESSION needs to be $_SESSION . . . Quote Link to comment https://forums.phpfreaks.com/topic/219570-please-help-me-oh-yee-magical-programming-masters/#findComment-1138467 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.