0

I have some difficulties understanding MySQLi and how it works. I recently upgraded my server to php7 and have to update some of my old MySQL compatible codes to MySQLi. I also want to fetch data from two different tables (users and accounts) from same database (db_secured) I read this is possible with join. I do not understand how to do all these with mysqli. Kindly help - here is my code:

<?
$acode=$_GET['account_number'];
$pin=$_GET['pin'];
include('../db.inc.php');
$sql=mysqli_query($mysqli,"SELECT users.pin, accounts.number FROM accounts, users WHERE number='$acode' AND pin='$pin'");
if(mysqli_num_rows($sql) == 0) {
    echo "invalid Account number or pin.";
}
else {
    $accounts=mysqli_fetch_array($sql);
    $users=mysqli_fetch_array($sql);
    $current_balance=$accounts['current_balance'];
    $available_balance=$accounts['available_balance'];
    $first_name=$user['first_name'];
    $last_name=$user['last_name'];

    echo "<sentence>Hello <prosody rate=\"-10%\">$first_name, $last_name</prosody></sentence>".
          "<sentence>Welcome message. </sentence>";
    echo "<sentence>net account balance is <prosody rate=\"-20%\">$current_balance</prosody></sentence>";
    echo "<sentence>available balance is <prosody rate=\"-20%\">$available_balance </prosody></sentence>";
}
  • When you change, take also a look at https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – nbk Jun 12 '20 at 10:08
  • The reference at https://stackoverflow.com/questions/1390607/how-to-change-mysql-to-mysqli gives insight to switching from MySQL to MySQLi but does not address the issue of fetching data from two separate tables from same database. – Leoben Osamah Jun 13 '20 at 07:01
  • I doesnä#zt matter it the same, when you take yyour posted query and use accounts ainner JOIN users u ON A.redid = u.id you have join bith and now you can get data from bot for msyqli or pdo ot doesn't matter it sees only the resultset. but still do leep in mind your code is **vulnerable to sql injection** – nbk Jun 13 '20 at 10:20

0 Answers0