0

Hi am trying to query the database and return the value to the client. So this is my code with two functions. The the rate is supposed to get the rate in the db.

    public function connect($description){

    //creating connection
    $con = new mysqli('localhost','root','','ci_vetro');
    //mysql_connect('localhost','root','') or die("Connection Error: ".mysql_error());
    //mysql_select_db('ci_vetro');

    //check connection
    if($con->connect_error):
        die('Connection Error: '. $con->connect_error);
    endif;

    $sql= "SELECT * from. exchange_rates where description=.'$description'.";
    $result= $con->query($sql);

    if($result->num_rows > 0):
        while($row = $result->fetch_assoc()) :
           $rate=$row["rate"]. "<br>";
        endwhile;
    else:
        echo "0";
    endif;

    $con->close();
    return $rate;

}
    public function getCurrency($currency) {

        $rate=connect($currency);

    switch ($currency){
        case 'USD':
            return int($rate);
        break;
        default:
          return 0;
        break;
    }
}
  • mysql->query returns false, if the query has a syntax error. so you try to get "num_rows" of a boolean variable. Enable the errors to see what happens. http://stackoverflow.com/a/21429652/4881521 – Djaevel May 19 '17 at 15:21
  • `$sql= "SELECT * from. exchange_rates where description=.'$description'.";` < ummmmm - those periods shouldn't be there - or you should be breaking and concatenating the string, one of the two. – CD001 May 19 '17 at 15:25
  • Sorry about that, alot of mistakes I did, and I managed to fix it. Thanks guys, I noticed my mistakes. – Lehlohonolo Motsoeneng May 23 '17 at 16:11

0 Answers0