TheAsker101 TheAsker101 - 3 months ago 28
PHP Question

Session variables in MySQL queries

Is it normal to use session variables in any kind of sql queries i make in Php.

this is just a example of what i did.

$result = mysqli_query($con,"select * from bookings where origin = $_session['location']);


is this the right way to do it? thanks

Answer

In php ,$_SESSION Most important object. You can easily handle everywhere in php file.

yes you can use it in your SQL query easily but with Right syntax . e.g. USE $_SESSION['location'] rather then $_session['location'] .. Now your Sql query would be

$result = mysqli_query($con,"select * from bookings where origin = $_SESSION['location']);