简体   繁体   中英

SQL / PHP not getting any results

I have this script and for some reason I'm getting "No Results".

$town_city = $_POST["town_city"];    
$partner_emails = "SELECT GROUP_CONCAT(email_address SEPARATOR ', ') FROM partners WHERE '$town_city' ='yes'";
$connect->query($partner_emails);
if ($result = $connect->query($partner_emails)) { 
    $row = $result->fetch_row();
    if(!empty($row[0])){
        $partner_emails = $row[0];
    }
    else {
        echo "Error: no results<br>";
        $partner_emails = false;
    }
    // CLOSE YOUR RESULTS
    $result->close();
}
else {
    echo "Error in the connection<br>";
    $partner_emails = false;
}
@mail($partner_emails, $supplier_subject, $supplier_message, $supplier_headers);

you're not getting results as your query is not ok.

$partner_emails = "SELECT GROUP_CONCAT(email_address SEPARATOR ', ') FROM partners WHERE '$town_city' ='yes'";

let's say, $town_city = 'ABC';

So your final query will be

$partner_emails = "SELECT GROUP_CONCAT(email_address SEPARATOR ', ') FROM partners WHERE 'ABC' ='yes'";

Here, you're messing things up. 'ABC' can't be a column it should be ABC

So your query will be like

$partner_emails = "SELECT GROUP_CONCAT(email_address SEPARATOR ', ') FROM partners WHERE $town_city ='yes'";
//$town_city without single quotes around it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM