This is a very strange problem I have never experienced before.
I perform these following stataments
//Grabs the currency from the bank account
$stmt = $db->prepare("SELECT * FROM accounts WHERE account_id = '$accountid'");
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$bankcurrency = $row['currency'];
}
}
$stmt->close();
//Finds the symbol of the speicific currency
$stmt = $db->prepare("SELECT * FROM currencies WHERE currency = ?");
$stmt->bind_param("s", $bankcurrency);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $symbol = $row['symbol'];
}
}
$stmt->close();
The output of the symbol from these statements are � The output should have been $
You would think I have something wrong with my database input, but no, because if I try:
$stmt = $db->prepare("SELECT * FROM currencies WHERE currency = 'USD'");
//$stmt->bind_param("s", $bankcurrency);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $symbol = $row['symbol'];
}
}
$stmt->close();
This then outputs $ This makes no sense as the data and statements are exactly the same.
You don't need to declare strings or variables in PHP which is why it makes no sense to me?
My database structure is simply:
accounts database:
name: currency
Type: TEXT
Value: USD
currencies database:
name: symbol
Type: TEXT
Value: $
Of course I have other rows, but these are the affected ones
You could say my database is the problem, but since the second statement works fine out outputs $ that is clearly not the problem.
I can't understand what is wrong
EDIT:
If I add in $bankcurrency = 'USD';
it also displays USD as you would expect, so there is a problem with my first statement