Hi Everyone, I have the following script to search for and display the CountryId (code) of a given country name.
$stmt = $conn->query('SELECT CountryId FROM countries WHERE Country = ".$clcountry." ');
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo $row['CountryId']; //etc...
}
I have tried the above with '.$clcountry.' and with $clcountry - The above is taken from the pdo php manual.
I have also tried the following
$sql = "SELECT CountryId FROM countries WHERE Country = '.$clcountry.'";
$stmt = $conn->prepare($sql);
$stmt->execute();
$total = $stmt->rowCount();
while ($row = $stmt->fetchObject()) {
$countryid = $row['CountryId'];
echo " $countryid
";
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
*/
As well as trying
$sql= "SELECT CountryId FROM countries WHERE Country = '.$clcountry.' ";
$stmt = $conn->query($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo $row['CountryId'];
When I simply echo the variable
echo "$clcountry";
I get the country name echo'd out on the page, but for some reason I am unable to echo the CountryId variable.
I thought it may have been a concatenate issue, but I have tried the different types of variations and still no luck.
Can someone tell me where or why this is not displaying the CountryId correctly please...