Jump to content

Use Session Data In Query


son

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...