jquery - Why is this running my separate php file when it shouldnt? -
i have multiple pages sorting out table based on specification. created page each table sort want on 1 page.
i have little snippet of code when log onto dashboard first time.
session_start(); $user = $_session['user']; if(empty($_session['table'])){ $_session['table'] = "dashboard"; }
i have jquery function @ bottom.
<script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> function changestring() { $.get("changestring.php"); return false; }
and have setup when click on image change string conditional , sort out out accordingly.
here's table conditional:
if($_session['table'] == "dashboard"){ $sql1=mysql_query("select email loggedin session_id='$user'"); $sess=mysql_fetch_array($sql1); $newvalue=$sess['email']; $sql2= mysql_query("select * food owneremail='$newvalue'"); } elseif($_session['table'] == "pantry"){ $sql1=mysql_query("select email loggedin session_id='$user'"); $sess=mysql_fetch_array($sql1); $newvalue=$sess['email']; $sql2= mysql_query("select * food owneremail='$newvalue' , container='pantry'");
here's img link:
<a href="#" onclick="changestring()";><img src="iconpantry.png" class="img-responsive"></a>
and here's separate php file called changestring.php
<?php session_start(); $_session['table'] = "pantry"; ?>:
now whats happening when first log in, reason automatically sets $_session['table'] = "pantry".
without me clicking on image.
why happening?
@user3503344 's answer correct fixes code reset session on login , didn't before. in general if setting not going consistent (i.e. resets each time user logins) better use variables.
what if user has 2 tabs of site open , wants different setting on each tab ? can't sessions .
so change table conditional to
if(!isset($_get['table']) || $_get['table'] == "dashboard"){ //this happens if ?table=x not exits or set dashboard $sql1=mysql_query("select email loggedin session_id='$user'"); $sess=mysql_fetch_array($sql1); $newvalue=$sess['email']; $sql2= mysql_query("select * food owneremail='$newvalue'"); }elseif($_get['table'] == "pantry"){ $sql1=mysql_query("select email loggedin session_id='$user'"); $sess=mysql_fetch_array($sql1); $newvalue=$sess['email']; $sql2= mysql_query("select * food owneremail='$newvalue' , container='pantry'"); }
and button should :
<a href="?table=pantry"><img src="iconpantry.png" class="img-responsive"></a>
this way user can bookmark site preferences doesn't have press button each time if wants see pantry table default .
Comments
Post a Comment