I have a rough program sketched thusly:
if (condition){
//redirect to some page
}
else{
echo $some_var;
}
So when I test is and the condition is true, it does the redirect, but also throws notices that there are undefined variables $some_var (that are pulled from a DB and WON'T be defined if the condition is true).
So does the code continue to evaluate after the if? This is not what I've expected.
If you want to dig, here's the actual code (it's CodeIgniter, but it's mostly self-documenting) and the test case is a garbage "gift code" that's not in the DB, so that count_all_results WILL == 0
. The notices thrown are that $uses is undefined.
$data['message'] = null;
//seeing if code is valid
$submitted_code = $_POST['code'];
$this->db->where('code', $submitted_code);
$this->db->from('codes');
if ($this->db->count_all_results() == 0){
$data['message'] = "This is not a valid gift code, sorry! You'll need to read our partner blogs, or listen to our favored Twitterers to find a valid code.";
$this->load->view('submission_form_view', $data);
}
else {
//seeing if code has any uses left
$this->db->where('code', $submitted_code);
$this->db->from('redemption_information');
$used_so_far = $this->db->count_all_results();
$this->db->select('uses');
$query = $this->db->get_where('codes', array('code' => $submitted_code));
foreach ($query->result() as $result)
{
$uses = $result->uses;
}
echo "Uses: $uses Used so far: $used_so_far <br />";
if ($uses <= $used_so_far) {
$this->load->view('over_used_view');
}
else
{
//these values are auto-escaped, so no worries on SQL injection
if ($this->db->insert('redemption_information', $_POST)) {
$data['message'] = "Your order has been taken, thanks for your interest!";
$this->load->view('success_view', $data);
}
else {
$data['message'] = "There was an error with your order. Please try again.";
$this->load->view('submission_form_view', $data);
}
}
}