This is the second part of my question from here:
Creating/editing a php dynamic page
I am now trying to put the code together. If you dont want to look at the first part of my question then ill tell you that i am experimenting and making a site that allows users to post events for a specific city. First the user uses a drop down menu to selct state, then on the next page they use a drop down menu to select the city. Once the city is selected they are taken to city.php where we use queries in our database to show events that people have posted for that particular city. Anyway i want to expand the city and turn city.php into the index where links to either events.php, jobs.php, or forsale.php will be located. When a user clicks on one of those links the particular city will still be remembered and a query will be done to pull out those info. Im just having problems coding:
Code from city drop down menu:
while($result = mysqli_fetch_array($doQuery)){
// $result contains id (cid) and name (cname) for each city
// $result - current row
// here we add HTML code for option "dynamically"
echo "<option value='".$result["cid"]."'>".$result["cname"]."</option>";
session_start();
$_SESSION['cname'] = $city;
code from city.php:
session_start();
$_SESSION['cname'] = $city;
// import dbconnect.php
// we use require(not include) to stop the script if such file does not exist
// we use "once" because we do not need to establish dbconnection if it already exists
require_once("dbconnect.php");
// all data which we get from cityByState.php are stored in $_POST superglobal array
// in our case we have only one field "city" so we can get city id from $_POST["city"]
// also we use intval function for security purposes. It converts variable to integer.
$cityId = intval($_REQUEST["city"]);
// query which gets all info about required city
$query = "select * from cities where id=$cityId";
// run the query and handle possible errors
if(!($doQuery = mysqli_query($db, $query))){
echo "Can not get info about the city!"; exit();
}
I am just a beginner and can't seem to understand how to properly use sessions to get my site to work properly. I am also not sure what i would use to insure that i can do the proper queries on the sub pages of city.php (events, jobs, forsale).