Jump to content

Use Session Data In Query


son
 Share

Recommended Posts

I would like to run a query with data from a session holding the relevant country. Running my query hard-coding a country works fine, but trying to store the session data in variable and use this one does not. The static working code is:

echo $_SESSION['country'];  $q = "SELECT country_id FROM countriesInt WHERE country = 'Austria' ";  $r = mysqli_query ($dbc, $q);  $row = mysqli_fetch_assoc ($r);  $country_id = $row['country_id'];  echo $country_id;

I tried:

 $ac = echo $_SESSION['country'];  $q = "SELECT country_id FROM countriesInt WHERE country = '$ac' ";  $r = mysqli_query ($dbc, $q);  $row = mysqli_fetch_assoc ($r);  $country_id = $row['country_id'];  echo $country_id;

but cannot get it work. Where am I going wrong?Son

Link to comment
Share on other sites

I assume you have set $_SESSION['country']try $ac = $_SESSION['country'] rather than $ac = echo $_SESSION['country']

Link to comment
Share on other sites

  • 5 weeks later...
I assume you have set $_SESSION['country']try $ac = $_SESSION['country'] rather than $ac = echo $_SESSION['country']
Thanks that did the trick. Sorry for late reply. I thought whole time I did get back to you already...Son
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...