PHP - Multiple $_session Variables Issue
When a user logs into my site I was to store the user_name, user_role, and user_id in a session variable, then store this in a regular variable to make querying easier, but I am having issues with my code as its causing issues with my queries.
Code: [Select] if (mysqli_num_rows($data) > 0) { //set sessions $row = mysqli_fetch_array($data); $_SESSION['username'] = $row['username']; $_SESSION['user_role'] = $row['role']; $_SESSION['user_id'] = $row['user_id']; //set variables $username = $_SESSION['username']; $user_role = $_SESSION['user_role']; $user_id = $_SESSION['user_id']; } Any ideas whats wrong?! Thanks for the help!! Similar TutorialsThe variable is set so the user can see the inside pages of a members area after they have logged in. By the time they go to a different page the variable is gone. Please note the following: - It doesn't happen to a specific browser - It doesn't happen all of the time - It works when I print the value of the $_SESSION variable - Once it has been printed to the screen once if I remove the functionality that makes it print, it keeps working. It's nearly impossible for me to test because I can't recreate the problem. It is my client that has the problem every once in a while. Please help!! I'm trying to use this php to clear out the session variables and return to the index page. However it's not clearing them out. Any ideas? logout.php Code: [Select] <?php session_start(); unset($_SESSION['user_id']); unset($_SESSION['username']); session_destroy(); header("Location: http://aaronhaas.com/pitchshark6/index.php?vid_id=1"); ?> then in my navigation I'm using this code to either display their username and a logout link to logout.php or if they are not logged in display a sign in link. Code: [Select] <?php // if logged in if (isset($_SESSION['user_id'])) { // display echo "<a href='#'>".$_SESSION['username']."</a> "; echo "<a href='scripts/logout.php'>Log Out</a> "; } // if not logged in else { // display login link echo "<a href='login.php'>Sign In</a>"; } ?> here is my super simple login script Code: [Select] $username = $_POST['username']; $password = $_POST['password']; //Check if the username or password boxes were not filled in if(!$username || !$password){ //if not display an error message echo "<center>You need to fill in a <b>Username</b> and a <b>Password</b>!</center>"; }else{ // find user by username and password - working $userQuery = 'SELECT * FROM users WHERE user_name ='.'"'. $username.'" AND password='.'"'. $password.'"' ; $users = mysql_query($userQuery); $user = mysql_fetch_array($users); $_SESSION['user_id'] = $user['user_id']; $_SESSION['username'] = $user['username']; header("Location: http://aaronhaas.com/pitchshark6/index.php?vid_id=1"); } Quote Hi guys, I have a question, I have a fairly large site wich we have resellers for, but in certain circumstances for admin purposes, we need to be able to login under the same credentials EG: I might be doing something on one machine and i need to log in on another machine to do something else but with my user name and pass At the moment when i try to to this It will log out the session already logged in when i try to log in from the other machine Is there away around this,, i suspect that when i log in from the other machine its ending the first session Any Idears Guys and Gals..... really stuck
First let me explain my code. This is later included in project_status.php] . In project_status.php] , I have included another file project_status_app.php which contains a HTML form.
<?php include 'inc_fn_header_and_menu.php'; function includeFile($file,$variable) { $var = $variable; include($file); } if (isset($_GET['id']) && $_GET['id']!="") { $pid = $_GET['id']; $_SESSION['pidForApproval'] = $_GET['id']; $query = 'SELECT * FROM `profile` WHERE pid ='.'\''.$pid.'\''; $result=mysqli_query($db,$queryToRetrievePP) or die("There are no records to display ... \n" . mysqli_error()); foreach ($result as $row) { $status = $row['status']; } } ...........some PHP and HTML code....... <div id="customerPurchaseApprovalForm"> <?php echo '<p>APPROVAL FOR CUSTOMER PURCHASE</p>'; $discountApprovalStatus = "Granted"; if ($discountApprovalStatus == "Granted") { includeFile("project_status_app.php",$highestannualvalue); } else { //......... } In project_status_app.php I am attempting to retrieve pidForApproval from the $_SESSION array. <?php // put your code here UPDATE `pp` SET `customer_purchase_remarks` = 'hahaha' WHERE `pp`.`id` = 207; if ($_SERVER['REQUEST_METHOD'] == 'POST') { include '../../inc/fastlogin.php'; $sql = "UPDATE pp SET customer_purchase_remarks ='{$_POST['remarkstxt']}' WHERE pp.pid='{$_SESSION['pidForApproval']}'"; $result = mysqli_query ( $fastdb, $sql ) ; if (mysqli_affected_rows($fastdb) != 1) { $_SESSION['err_cpa_rmks'] = "<p>Error while updating WHERE id='{$_SESSION['pidForApproval']}'</p>"; //echo "<p>Error while updating WHERE id='{$_POST['pidForApproval']}'</p>".mysqli_error($fastdb); } else { $_SESSION['suc_cpa_rmks'] = "<p>Records was updated successfully.</p>"; //echo "Records was updated successfully."; } header ("location: project_status.php?id="$_SESSION['pidForApproval']); exit(); } ?> When I load project_status.php, project_status_app.php is supposed to display the form. Once the user fills in the form the and the submit button has been pressed, the UPDATE statement is supposed to run and then it is supposed to navigate back to project_status.php?id=FA142. But the update is failing and the when the project_status.php is loaded back, the url looks like this http://localhost/fast/project_status.php?id= . The id is empty. It is supposed to be something like this http://localhost/fast/project_status.php?id=FA142. With the id being populated at the header ("location: project_status.php?id=".$_SESSION['pidForApproval']);
Missing some information. Hello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> I have a form with multiple options to fill out (its a admin form) i want to make sure only one of the of the options are set, so im checking if the variable is empty with if ($variable1 != NULL) { $new_variable = "yep, this option was filled out"; } so if the form sent anything from the form with the value 'variable1' it then sets a new variable ($new_variable) Problem is i have multiple fields so i need to make sure if it finds a a variable is not empty, then too check if the others have anything in them too. If it does find another (meaning more than one has been filled out) echo an error (echo "you must only complete one option..") What is the best way to check if more than one variable exists? Sorry if i explained it complicated. Thank you Hello everyone, I'm sitting here in a position where I can't work on my site or test any code, but my mind is racing about what I can do to solve a particular problem that I have. I won't get into the problem because it would take more time to type than I have right now, but I have an idea for a simple solution, just not sure if it will work or not. So, here's my question: Is it possible to have multiple session variables during a session? Such as: $email=$_SESSION['email']; $user=$_SESSION['userid']; If this is possible, my problem is solved (I think)... otherwise, I have to keep thinking about it. Thanks for any help! Is there anyway I can like "exit" the variables so i can use the same variable name later in the page? I have this function: Code: [Select] function echo_exist($pre1,$ee,$post1) { if ($ee!='') { return $pre1; return $ee; return $post1; } else { //do nothing } } But when I try to echo it Code: [Select] echo_exist("(","$row['payment_type']",")"); I get syntax error, unexpected T_ENCAPSED_AND_WHITESPACE If $row['payment_type'] exists, I want it to be displayed in parentheses like: (AUTO) I suspect it has to do with my ' characters for the associative array, but I am new with functions so perhaps it is the multiple arguments that are wrong? Hi, I'm having a bit of a problem sharing some variables I have across a few files. My first file (index.php) calls an ajax request for (display.php) and sends a few variables to it. All fine so far. display.php then does its thing and displays the content on index.php as it should. Now in display.php I need a variable to be passed back to index.php for use in a menu. I've tried setting a session variable in display.php but unfortunately this doesn't seem to work. I also can't use get or post as I don't want to refresh the page. Really scratching my head over this one! Edd Hi, I want to send the following variable using the $_GET function: hello, im wondering how to properly code the following. Code: [Select] $stdate = date( 'Ymd', strtotime($pdate) ); $sttime = date( 'His', strtotime($tstart1) ); $dtStart = ".$stdate.'T'.$sttime.'Z'"; echo "$dtStart"; i would like the echo to read 20110309T050000Z I am creating a webpage for my golf league and some of the information(variables) such as Name, Address and email, must be reused across multiple pages for different outputs. May question is "Can I, or is there a way to reUse variables across multiple pages. "Do I need to create a session and make everything session variables"? "Should I link to a database and call the information when needed"? Any explanation would be greatly appreciated. Hi Guys and Girls, Long time lurker, first time poster! I am usually able to read through the forums and find and answer without having to start a new thread but I've tried my best to no avail. I am having trouble with the following code: $afname="Gareth"; $alname="B"; $awayoption.="<OPTION VALUE=\"".$afname." \"".$alname."\">".$afname." ".$alname; I would want that to produce the following: Code: [Select] <OPTION VALUE=Gareth B">Gareth B The actual result at the moment is: Code: [Select] <OPTION VALUE="Gareth "B">Gareth B It has an extra " in the middle. Any ides or help would be great! Cheers
I have a webpage that I am working on that is now in construction mode. The url is: https://localbizseek.com/lbs/index6 The problem is that I want to it to be able to search 2 at the same time in the phpmyadmin database table which is named "places". I also want to be able to get to search all 9 cities for that area. There are a total of 36,000+ cities in the database. However, I want it to be able to search just 2 or 9 specific cities of those cities. Each city has a city_id which is an integer assigned to it in the database Right now it will search only 1 city at a time or it will search every city in the database if I assign the search variable as "" or "0". I don't know what to do on this page to solve it and on the related processing page. Here is the code on the webpage: <form id="main-search-form" method="GET" action="<?= $baseurl; ?>/_searchresults.php" role="search"> <select id="query-input" name="city_id" style="width:28.8%" style="height:69px" required> <option value="">Select Area</option> <option value="3;1">Ches & VB</option> <option value="3">Chesapeake , VA</option> <option value="9">Hampton , VA</option> <option value="10">Newport News , VA</option> <option value="2">Norfolk , VA</option> <option value="12">Poquoson , VA</option> <option value="4">Portsmouth , VA</option> <option value="5">Suffolk , VA</option> <option value="1">Virginia Beach , VA</option> <option value="11">Williamsburg , VA</option> <option value="0">All Active US Cities</option> </select> </form>
You will notice that I have tried "3;1" up under the Ches & VB Select Option but that doesn't work because it will not work that way. I can have it as "3 1" but then it just displays 1 which is VB's information. I've tried everything possible and it won't search both variables. It only will search one. <form id="main-search-form" method="GET" action="<?= $baseurl; ?>/_searchresults.php" role="search"> <select id="query-input" name="city_id" style="width:28.8%" style="height:69px" required> <option value="">Select Area</option> <option value="3,1">Ches & VB</option> <option value="3">Chesapeake , VA</option> <option value="9">Hampton , VA</option> <option value="10">Newport News , VA</option> <option value="2">Norfolk , VA</option> <option value="12">Poquoson , VA</option> <option value="4">Portsmouth , VA</option> <option value="5">Suffolk , VA</option> <option value="1">Virginia Beach , VA</option> <option value="11">Williamsburg , VA</option> <option value="0">All Active US Cities</option> </select>
Here is the final page of code which I'm not sure if this one needs changing but just in case here it is: <!DOCTYPE html> <!--[if IE 9]><html class="lt-ie10" lang="<?= $html_lang; ?>"> <![endif]--> <html class="no-js" lang="<?= $html_lang; ?>"> <head> <title><?= $txt_html_title; ?> - <?= $site_name; ?></title> <meta name="description" content="<?= $txt_meta_desc; ?>" /> <meta name="robots" content="noindex"> <?php require_once('_html_head.php'); ?> </head> <body class="tpl-searchresults"> <?php require_once('_header.php'); ?> <h1><?= $txt_main_title; ?></h1> <div class="full-block"> <div class="content-col"> <div class="list-items"> <?php /* -------------------------------------------------- BEGIN SHOW LIST -------------------------------------------------- */ if($total_rows > 0) { $count = ($page - 1) * $limit; $results_arr = array(); foreach($list_items as $k => $v) { $count++; $place_id = $v['place_id']; $place_name = $v['place_name']; $place_slug = $v['place_slug']; $address = $v['address']; $cross_street = $v['cross_street']; $place_city_name = $v['place_city_name']; $place_city_slug = $v['place_city_slug']; $place_state_abbr = $v['place_state_abbr']; $postal_code = $v['postal_code']; $area_code = $v['area_code']; $phone = $v['phone']; $phone = preg_replace("/[^0-9]/", "", $phone); $phone = substr($phone, 0, 3) . '-' . substr($phone, 3); $lat = $v['lat']; $lng = $v['lng']; $cat_icon = $v['cat_icon']; $photo_url = $v['photo_url']; $rating = $v['rating']; $description = $v['description']; $results_arr[] = array( 'ad_id' => $place_id, 'ad_lat' => $lat, 'ad_lng' => $lng, 'ad_title' => $place_name, 'count' => $count, 'cat_icon' => $cat_icon); $places_names_arr[] = $place_name; ?> <div class="item" data-ad_id="<?= $place_id; ?>"> <div class="item-pic" id="<?= $place_id; ?>"> <img src="<?= $photo_url; ?>" /> </div><!-- .item-pic --> <div class="item-description"> <div class="item-title-row"> <div class="item-counter"><div class="item-counter-inner"><?= $count; ?></div></div> <h2><a href="<?= $baseurl; ?>/<?= $place_city_slug; ?>/place/<?= $place_id; ?>/<?= $place_slug; ?>" title="<?= $place_name; ?>"><?= $place_name; ?></a></h2> </div> <div class="item-ratings-wrapper"> <div class="item-rating" data-rating="<?= $rating; ?>"> <!-- raty plugin placeholder --> </div> <div class="item-ratings-count"> <?php // echo $count_rating; ?> <?php // echo ($count_rating == 1 ? 'review' : 'reviews'); ?> </div> <div class="clear"></div> </div><!-- .item-ratings-wrapper --> <div class="item-info"> <div class="item-addr"> <strong> <?= (!empty($address)) ? $address : ''; ?> </strong> <?= (!empty($cross_street)) ? "($cross_street)" : ''; ?> <br> <strong> <?= (!empty($place_city_name)) ? "$place_city_name," : ''; ?> <?= (!empty($place_state_abbr)) ? " $place_state_abbr " : ''; ?> <?= (!empty($postal_code)) ? $postal_code : ''; ?> </strong> </div> <div class="item-phone"> <?= (!empty($phone)) ? '<i class="fa fa-phone-square"></i>' : ''; ?> <?= (!empty($area_code)) ? $area_code : ''; ?> <?= (!empty($phone)) ? $phone : ''; ?> </div> </div><!-- .item-info --> <?php echo (!empty($tip_text)) ? $tip_text : ''; ?> </div><!-- .item-description --> <div class="clear"></div> </div><!-- .item --> <?php } // end foreach($response as $k => $v) } // end if($total_rows > 0) else { // else no results found ?> <div class="empty-cat-template"> <p><?= $txt_empty_results; ?></p> </div> <?php } ?> </div><!-- .list-items --> <?php /* -------------------------------------------------- BEGIN PAGER -------------------------------------------------- */ ?> <div id="pager"> <ul class="pagination"> <?php if(!empty($pager) && $pager->getTotalPages() > 1) { $curPage = $page; $startPage = ($curPage < 5)? 1 : $curPage - 4; $endPage = 8 + $startPage; $endPage = ($pager->getTotalPages() < $endPage) ? $pager->getTotalPages() : $endPage; $diff = $startPage - $endPage + 8; $startPage -= ($startPage - $diff > 0) ? $diff : 0; $startPage = ($startPage == 1) ? 2 : $startPage; $endPage = ($endPage == $pager->getTotalPages()) ? $endPage - 1 : $endPage; if($total_rows > 0) { $page_url = "$baseurl/_searchresults.php?city_id=$query_city_id&query=$query_query&page="; if ($curPage > 1) { ?> <li><a href="<?= $page_url; ?>1">Page 1</a></li> <?php } if ($curPage > 6) { ?> <li><span>...</span></li> <?php } if ($curPage == 1) { ?> <li class="active"><span>Page 1</span></li> <?php } for($i = $startPage; $i <= $endPage; $i++) { if($i == $page) { ?> <li class="active"><span><?= $i; ?></span></li> <?php } else { ?> <li><a href="<?php echo $page_url, $i; ?>"><?= $i; ?></a></li> <?php } } if($curPage + 5 < $pager->getTotalPages()) { ?> <li><span>...</span></li> <?php } if($pager->getTotalPages() > 5) { $last_page_txt = "Last Page"; } $last_page_txt = ($pager->getTotalPages() > 5) ? "Last Page" : $pager->getTotalPages(); if($curPage == $pager->getTotalPages()) { ?> <li class="active"><span><?= $last_page_txt; ?></span></li> <?php } else { ?> <li><a href="<?php echo $page_url, $pager->getTotalPages(); ?>"><?= $last_page_txt; ?></a></li> <?php } } // end if($total_rows > 0) } // end if(isset($pager) && $pager->getTotalPages() > 1) if(isset($pager) && $pager->getTotalPages() == 1) { ?> <?php } ?> </ul> </div><!-- #pager --> </div><!-- .content-col --> <div class="sidebar"><div class="clear"></div> <?php if($total_rows > 0) { ?> <div class="clear"></div> <div class="map-wrapper" id="sticker"> <div id="map-canvas" style="width:100%; height:100%"></div> </div> <?php } ?> </div> <div class="clear"></div> <!-- #sidebar --> <div class="clear"></div> </div><!-- .content-full --> <?php require_once('_footer.php'); ?> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<?= $google_key; ?>"></script> <script type="text/javascript"> // place markers var results_obj = <?php echo json_encode($results_arr); ?>; var infowindow; var map; function initialize() { markers = {}; infoboxcontents = {}; // set map options var mapOptions = { zoom: 1 }; // instantiate map var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); var bounds = new google.maps.LatLngBounds(); var infowindow = new google.maps.InfoWindow(); // $results_arr[] = array("ad_id" => $place_id, "ad_lat" => $ad_lat, "ad_lng" => $ad_lng, "ad_title" => $ad_title, "count" => $count); // set markers for (var k in results_obj) { var p = results_obj[k]; var latlng = new google.maps.LatLng(p.ad_lat, p.ad_lng); bounds.extend(latlng); var marker_icon = '<?= $baseurl; ?>/imgs/marker1.png'; // place markers var marker = new google.maps.Marker({ position: latlng, map: map, animation: google.maps.Animation.DROP, title: p.ad_title, //icon: marker_icon }); markers[p.ad_id] = marker; infoboxcontents[p.ad_id] = p.ad_title; // click event on markers to show infowindow google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(this.title); infowindow.open(map, this); }); } // end for (var k in results_obj) map.fitBounds(bounds); $(".list-items .item").mouseover(function() { marker = markers[this.getAttribute("data-ad_id")]; // mycontent = infoboxcontents[this.getAttribute("data-ad_id")]; mycontent = '<div class="scrollFix">' + infoboxcontents[this.getAttribute("data-ad_id")] + '</div>'; // console.log(mycontent); infowindow.setContent(mycontent); // infowindow.setOptions({maxWidth:300}); infowindow.open(map, marker); marker.setZIndex(10000); }); // end mouseover } // end initialize() google.maps.event.addDomListener(window, 'load', initialize); </script> <script type="text/javascript"> $.fn.raty.defaults.path = '<?= $baseurl; ?>/templates/lib/raty/images'; $('.item-rating').raty({ readOnly: true, score: function(){ return this.getAttribute('data-rating'); } }); </script> <script> $(document).ready(function(){ $("#sidebar").sticky({topSpacing:0}); }); </script> <script> $(document).ready(function(){ $("#sticker").sticky({topSpacing: 24}); }); </script> <script type="text/javascript"> function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes.split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; } $(document).ready(function() { var loc = '<?= e($_GET['loc']); ?>'; var query = '<?= e($_GET['query']); ?>'; if(loc !== '') { $("#city-input").val(loc); } if(query !== '') { $("#query-input").val(query); } }); </script> </body> </html> Edited April 13, 2019 by requinix please use the Code <> button when posting code. This will only send 1 goggles information into the database but I have a "adding" page that can actually add more than 1 goggles at once. I have no idea how to go about saving multiple goggle's information using array or loop. $name= $_POST['goggles_name']; $price = $_POST['goggles_price']; $des = $_POST['goggles_description']; $file = $_FILES['goggles_image']['name']; $chkbox = $_POST['upload']; $id = $_POST['goggles_id']; $query = "UPDATE goggles SET goggles_name = '$name' , goggles_price = '$price' ,goggles_description = '$des' WHERE goggles_id ='".$id."' "; $result = mysqli_query($link, $query) or die(mysqli_error($link)); Hi, I have an affiliate system that shows results on what product is purchased. The problem is that the tracker is only listing the first product in the purchase list, so if someone purchases multiple products it only shows the first product in the transaction report. Here is the code: Code: [Select] $module = fetchDbConfig('PostAffiliatePro'); $orderInv = $order->getOrderInv($_GET["cart_order_id"]); print_r($orderInv); $affCode = "<!-- Begin PostAffiliatePro Affiliate Tracker --> <img border='0' src='".$module['URL']."/scripts/sale.php?TotalCost=".sprintf("%.2f", $orderSum['subtotal'])."&OrderID=".$cart_order_id."&ProductID=".$orderInv['0']['productCode']."' width='0' height='0' alt='' /> <!-- End PostAffiliatePro Affiliate Tracker -->"; ?> The code I need help with syntax is: Code: [Select] "&ProductID=".$orderInv['0']['productCode']."The products are split into arrays by number (0,1,2,3). So for example, I would want to show results for .$orderInv['0']['productCode']. , then .$orderInv['1']['productCode']. , and so on. I would like the results to be posted with a ; between them, but I don't know the proper syntax to have it report more than just the first array. This seems pretty simple, but I only know the basics of PHP and I've adapted this from found code. Any guidance would be greatly appreciated. Thanks! hello i have built a webpage using tables. i might have done something wrong (except using tables) and now the results are rendered chaotically on the webpage. also here is the attached file. after the 4th article it's all messy i have a solution but that means to insert a php tag inside another php tag, but won't work thankyou Hi All, I'm quite new to this PHP stuff and have been creating a site just for the hell of it really but i have a rather bizarre problem that has been driving me nuts for about a week... I have two drops downs, the first gives a list of teams from a mysql table and then this populates the next drop down with a list of players from the selected team.. so far so good. When I hit the select/submit button to select the player, what should happen is both the "team" and "player" are put into another query which gives the stats on the selected player for all the games that he has played in. however, what actually happens in the Session variable sets the "team" variable to blank. I can see this happening when I use Print_r ($_SESSION); So essentially when I click on either submit button from my drop down forms the other value is being removed from the Session array. Oh, the session is still valid (not being destroyed and replaced with another session). First drop down $query_teams="select Team from $teams"; $team_result=mysql_query($query_teams); $num_team=mysql_numrows($team_result); echo $num_team; print_r ($row_team); $team_count = 0; echo '<form method="post" action="map_selector.php">'; echo "<SELECT name='country'>"; while ($row_team1 = mysql_fetch_assoc($team_result)) { $team_info = $row_team1["Team"]; echo "<OPTION value='$team_info'>$team_info </option>"; } echo '</select>'; echo '<center><input type="submit" value="Search"></center>'; $country = $_POST["country"]; $_SESSION["country"] = $country; echo '</form>'; So SCOTLAND is selected Some sql queries to get the results for the possible players and then Drop down 2 $row_full = array_unique($row_home); echo '<form method="post" action="map_selector.php">'; echo "<SELECT name='Player'>"; foreach ($row_full as $key => $value) { echo "<OPTION value='$value'> $value"; } echo '</select>'; echo "@"; echo $country; echo "@"; echo '<center><input type="submit" value="Search"></center>'; $country=$_POST["country"]; $player=$_POST["Player"]; echo "#"; echo $country; echo "#"; echo '</form>'; $_SESSION["Player"] = $player; $selected_player = $_SESSION["Player"]; echo $player; echo $selected_player; echo $country; Print_r ($_SESSION); so Print_r ($_Session) returns: Array ( [Player] => [country] => Scotland [] => ) then a player "Paul Hartley" is selected from the player list and submit is click and then Print_r($_Session) shows: Array ( [Player] => Paul Hartley [country] => [] => ) Can anyone please help... I just can;t understand why this is happening when I'm using a Sessions which, I thought, would retain all variable values until a time-out or a destroy Thanks nhsal69 Suppose I have two versions of the same website; one American and one Canadian. This site has members with profiles etc. The way my site is written, I think that if someone were to login to their account on, say, the American site, then a session variable would indicate that a user is logged in on the client machine. Now if they visit the "profile" page, for example, or some other members-only page ON THE CANADIAN SITE, and start manipulating data etc., then this would affect the databases for the Canadian site, and everything would get screwed up (actually, I think mysql would just start spitting out errors, but that's not good either). Does anyone have some simple way to deal this this kind of thing? I don't really know exactly how session variables work. Say I have two domains, somepage.com and somepage.ca on the same server/DNS. If a page on somepage.com sets a session variable called $_SESSION['somevar'], and a page on somepage.ca also sets a variable called $_SESSION['somevar'], are the two variables somehow distinct because they are on different domains? Like, if somepage.com sets the variable, then somepage.ca check if the variable is set, what will happen? What if I wanted to set up the two pages in subfolders, like somepage.com/us and somepage.com/ca, how would I deal with distinguish session variables for the two sites? Is one approach (i.e. distinct domains vs subfolders) better than the other? Thanks, |