3

I am conventing old mysql to mysqli and run into a problem, which is that my mysqli_connect will not work in any my functions. after looking on the internet I found that it was a scope problems so i passed the mysqli_connect variable on to the function. which did not work. here are my two error

Notice: Undefined variable: con in C:\xampp\htdocs\bear_mysqli\functions\cart.php on line 44

Warning: Missing argument 1 for products(), called in C:\xampp\htdocs\bear_mysqli\shop.php on line 30 and defined in C:\xampp\htdocs\bear_mysqli\functions\cart.php on line 40

$con = mysqli_connect("localhost","root","","bear") or die ($connect_error);

function products($con)
{
    $get = mysqli_query($con,'SELECT * FROM items WHERE quantity > 0 ORDER BY id DESC ');
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
hobbit
  • 59
  • 7

1 Answers1

-1
function f1(){
  $get = mysqli_query($GLOBALS['con'], "SELECT * FROM location");
}

If you write $GLOBALS['con'] then $con variable is treated as global so you can use it now in any function.

Tim Lewis
  • 27,813
  • 13
  • 73
  • 102
Dharini
  • 1
  • 2