Jump to content

Isset not cooperating


Recommended Posts

I'm trying to make the following code work and can't seem to figure it out. I know it has to do with the line I commented on, but can't figure out how to make it work.

 

I've tried a few different ways with no luck. It's this part "] == "'.$status.'")" I've tried "$status", "'.$status.'", '.$status.','$status' ...Any idea?

 

function showresults($conn) {

// DEFAULT RESULTS

    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'New' ORDER BY date DESC");

// STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed')

$status = $_GET['status'];

    if(isset($_GET['status']) && $_GET['status'] == "'.$status.'") // THIS IS THE ISSUE, JUST NOT SURE HOW TO WRITE $status after ==
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '.$status.' ORDER BY date DESC");

// BIND AND EXECUTE

	$stmt->execute();
	$stmt->bind_result($ID,$date,$firstname,$lastname,$spousefirst,$spouselast,$primarybday,$spousebday,$phonecell,$phonehome,$phoneoffice,$spousecell,$phoneother,$email,$emailspouse,$emailother,$emailspouseother,$address,$suite,$city,$state,$zipcode,$addressother,$suiteother,$cityother,$stateother,$zipcodeother,$agentassigned,$contacttype,$status,$contactsource,$timing,$password,$subscribesearches,$subscribedrips);

    while ($stmt->fetch()) {

    echo'
             <tr>
				<td><input type="checkbox" name="checked[]" value="'.$ID.'"></td>
			<td><a href="/cms/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td>
			<td>'.$phonecell.'</td>
			<td><a href="mailto:'. $email.'">'.$email.'</a></td>
			<td>'.date("M jS, g:i A", strtotime($date)).'</td>
			<td>'.$contactsource.'</td>
			<td>'.$status.'</td>
			<td>'.$contacttype.'</td>
			<td>'.$agentassigned.'</td>
			<td><a href="/cms/contacts/notes.php?ID='.$ID.'">V </a>+</td>
			<td><a href="/cms/contacts/todo.php?ID='.$ID.'">V </a>+</td>
			<td><a href="javascript: removelead('.$ID.')">D</a></td>
           </tr>';
}

}

Link to comment
Share on other sites

Since you've just assigned the value from $_GET['status'] to $status in the previous line of code, there is no need for the $_GET['status'] == $status comparison at all. If you 're trying to make sure $status contains one of the values from the list you have above that (new, hot, warm, etc. . . ), you should put those values in an array and use in_array instead.

Link to comment
Share on other sites

Since you've just assigned the value from $_GET['status'] to $status in the previous line of code, there is no need for the $_GET['status'] == $status comparison at all. If you 're trying to make sure $status contains one of the values from the list you have above that (new, hot, warm, etc. . . ), you should put those values in an array and use in_array instead.

 

I see what you're saying, I was trying to prevent from having to create an array with (new, hot, warm, etc. . . )  because if a user adds a new status type, to the database(contactstatus), I would have to manually go in and change the array, does that make sense?

 

 

Link to comment
Share on other sites

No, it doesn't make sense really. You could just as easily run a SELECT COUNT() query to verify whether the value is a valid status or not, but I'm not sure I'd let users edit things like that.

 

I'll try to explain, maybe I'm approaching this wrong and you can help straighten me out.

 

Here is what I had before:

 

    if(isset($_GET['status']) && $_GET['status'] == "New")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'New' ORDER BY date DESC");

    if(isset($_GET['status']) && $_GET['status'] == "Hot")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Hot' ORDER BY date DESC");

    if(isset($_GET['status']) && $_GET['status'] == "Warm")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Warm' ORDER BY date DESC");

    if(isset($_GET['status']) && $_GET['status'] == "Cold")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Cold' ORDER BY date DESC");

    if(isset($_GET['status']) && $_GET['status'] == "Rejected")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Rejected' ORDER BY date DESC");

    if(isset($_GET['status']) && $_GET['status'] == "Closed")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Closed' ORDER BY date DESC");

 

Here is what I'm trying to change it to so that if a user adds a new status type into the database it's automatically available to search by (in other words, I don't have to go in and create a new line as in the above code.

 

	$status = $_GET['status'];

    if(isset($_GET['status']) && $_GET['status'] == "'.$status.'")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '.$status.' ORDER BY date DESC");

Link to comment
Share on other sites

$_GET['status'] == "'.$status.'"

will never be true, if you're defining

$status = $_GET['status'];

 

Are you trying to validate that status is a valid option? If so, you're going to have to manually define the array, or build the array form this list of allowed values in the database, and check against that.

Link to comment
Share on other sites

$_GET['status'] == "'.$status.'"

will never be true, if you're defining

$status = $_GET['status'];

 

Are you trying to validate that status is a valid option? If so, you're going to have to manually define the array, or build the array form this list of allowed values in the database, and check against that.

 

Not validate that status is a valid option. Instead, what I want is for the leads that have just the status 'Hot' to show or 'Cold' or 'New'. So, what I have is a dropdown with all the options (New, Hot, Cold, etc.) and when one is selected it only displays those leads.

 

Previously I had each one with a statement

 

    if(isset($_GET['status']) && $_GET['status'] == "New")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'New' ORDER BY date DESC");

    if(isset($_GET['status']) && $_GET['status'] == "Hot")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Hot' ORDER BY date DESC");

 

And what I want to do is something like this (but it's not working):

 

    if(isset($_GET['status']) && $_GET['status'] == '.$status.')
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '.$status.' ORDER BY date DESC");

Link to comment
Share on other sites

You're over-complicating this.

 

<?php

$query =
"SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,
	phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,
	emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,
	stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,
	password,subscribesearches,subscribedrips
FROM contacts
WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor')";

if(isset($_GET['status'])) {
$status = $conn->escape_string($_GET['status']);
$query .= " AND STATUS = '$status'";
}
$query = " ORDER BY date DESC";

$conn->prepare($query);

?>

Link to comment
Share on other sites

other alternative (maintaining 'NEW' as the Default option):

 

   function showresults() {

    // DEFAULT
    $status = 'NEW';
    
    // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed')
    if (isset($_GET['status']) && !empty($_GET['status'])) {
        $status = $conn->escape_string($_GET['status']);
    }
    
    $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,
                       spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,
                       email,emailspouse,emailother,emailspouseother,address,suite,city,
                       state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,
                       agentassigned,contacttype,status,contactsource,timing,password,
                       subscribesearches,subscribedrips 
                  FROM contacts 
                  WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') 
                  AND status = '$status' 
                  ORDER BY date DESC";
    
   $stmt = $conn->prepare( $query);

Link to comment
Share on other sites

other alternative (maintaining 'NEW' as the Default option):

 

   function showresults() {

    // DEFAULT
    $status = 'NEW';
    
    // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed')
    if (isset($_GET['status']) && !empty($_GET['status'])) {
        $status = $conn->escape_string($_GET['status']);
    }
    
    $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,
                       spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,
                       email,emailspouse,emailother,emailspouseother,address,suite,city,
                       state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,
                       agentassigned,contacttype,status,contactsource,timing,password,
                       subscribesearches,subscribedrips 
                  FROM contacts 
                  WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') 
                  AND status = '$status' 
                  ORDER BY date DESC";
    
   $stmt = $conn->prepare( $query);

 

THIS IS EXACTLY WHAT I WAS LOOKING FOR!!!! THANK YOU!!!

 

ALSO THANKS TO EVERYONE ELSE WHO CHIMED IN TO HELP!!!! MUCH APPRECIATED!!!

Link to comment
Share on other sites

other alternative (maintaining 'NEW' as the Default option)

 

Here is another challenge...Lets say I have another dropdown box on the page with Sources (Website, Referral, etc.) How would I add this in to the function?

 

So I have:

 

function showresults($conn) {

// DEFAULT RESULTS

    $status = 'New';

// STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed')

if (isset($_GET['status']) && !empty($_GET['status'])) {
$status = $conn->escape_string($_GET['status']);
}

$query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '$status' ORDER BY date DESC";

$stmt = $conn->prepare($query);

// SOURCE RESULTS

    if(isset($_GET['contactsource']) && $_GET['contactsource'] == "Website")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND contactsource = 'Buzz' ORDER BY date DESC");

    if(isset($_GET['contactsource']) && $_GET['contactsource'] == "Referral")
    $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND contactsource = 'Expired' ORDER BY date DESC");

 

Because if I do the following, the DEFAULT and STATUS RESULTS DON't SHOW UP

 

function showresults($conn) {

// DEFAULT RESULTS

    $status = 'New';

// STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed')

if (isset($_GET['status']) && !empty($_GET['status'])) {
$status = $conn->escape_string($_GET['status']);
}

$query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '$status' ORDER BY date DESC";

$stmt = $conn->prepare($query);


// SOURCE RESULTS ('Website', 'Referral',)

if (isset($_GET['contactsource']) && !empty($_GET['contactsource'])) {
$contactsource = $conn->escape_string($_GET['contactsource']);
}

$query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND contactsource = '$contactsource' ORDER BY date DESC";

$stmt = $conn->prepare($query);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.