dave1234 Posted December 29, 2012 Share Posted December 29, 2012 I am using button to subscribe/unsubscribe from articles. When an user click the the button I change the text to subscribed/unsubscribed. The problem is that after the user refresh the page, the button enabled and show the text Subscribe/Unsubscribe accordingly. when the user click the button no action takes place and change the text with text from previous action. ex. user login. click Subscribe button from the article page. - database action done - button text change to Subscribed, disabled User refresh the page. click Unsubscribe button - no db action takes place - button text change to Subscribed, disabled If the browser closed and reopen then the user can unsubscribe. To subscribe again, close and reopen the browser. how to fix this? Quote Link to comment Share on other sites More sharing options...
trq Posted December 29, 2012 Share Posted December 29, 2012 You will need to show us an example. Quote Link to comment Share on other sites More sharing options...
dave1234 Posted December 29, 2012 Author Share Posted December 29, 2012 Lets say we want to add subscribe/unsubscribe feature on this forum(ignore default feature). So members can click the button to subscribe/unsubscribe to/from the thread. how would you do it? Quote Link to comment Share on other sites More sharing options...
trq Posted December 29, 2012 Share Posted December 29, 2012 Your going to need to let us know where exactly you are stuck. I meen, all you would need do is add a button that toggle between a user being subscribed or not. Sounds super simple to me. Quote Link to comment Share on other sites More sharing options...
dave1234 Posted December 29, 2012 Author Share Posted December 29, 2012 Thank you for reply. How to clear cache from visitor's browser so they dont have to close and re-open the browser? Quote Link to comment Share on other sites More sharing options...
trq Posted December 29, 2012 Share Posted December 29, 2012 Your question makes little sense. Quote Link to comment Share on other sites More sharing options...
dave1234 Posted December 29, 2012 Author Share Posted December 29, 2012 what is cleared when browser closed and re-open? Is that cache causing the problem? If so I dont' want to cache my articles on visitor's computer. how can I do that? Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 29, 2012 Share Posted December 29, 2012 This went from making little sense to making no sense. Quote Link to comment Share on other sites More sharing options...
dave1234 Posted December 29, 2012 Author Share Posted December 29, 2012 (edited) I'm using the following code in three places. <? if(user_check_status()) { $que = "select * from ar_usersub where userID=".$_SESSION['UserPkID']." and articleID=".$myArt['articleID']; $result =mysql_query($que); if(mysql_num_rows($result)){ $val = "Unsubscribe"; } else { $val ="Subscribe"; } ?> <div width="10%"> <div id="subscribeDiv"><input type="submit" name="subscribe" value="<?echo $val;?>" onclick="checkStatus()"/></div></div> <? } ?> javascript/Ajax <script language="Javascript" type="text/Javascript"> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function checkStatus() { var strURL="/subscribe.php?eId="+<?echo $myArt['articleID'];?>+"&uId="+<?echo $_SESSION['UserPkID'];?>; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('subscribeDiv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> subscribe.php <? $val=($_GET['eId'] + $_GET['uId']); $us = $_GET['uId']; $ev = $_GET['eId']; $link = mysql_connect('localhost', 'xxxxx', 'xxxx'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('xxxx'); $que = "select * from ar_usersub where userID=".$us." and articleID=".$ev; $result =mysql_query($que); $que2=""; if(mysql_num_rows($result)){ $que2 = "delete from ar_usersub where userID=".$_GET['uId']." and articleID=".$_GET['eId']; $val = "Unubscribed"; } else { $que2 = "insert into ar_usersub values(".$us.", ".$ev.")"; $val ="Subscribed"; } mysql_query($que2); ?> <div id="subscribeDiv2"><input id=<?echo $val;?> type="submit" name=<?echo $val;?> value=<?echo $val;?> disabled="disabled" /></div> Front End actions: user login. click Subscribe button from the article page. - database action done - button text changed to Subscribed & the button disabled User refresh the page. click Unsubscribe button (since the user already subscribed the Unsubscribe button displayed) - no db action takes place - button text change to Subscribed & the button disabled If the browser closed and reopen then the user can unsubscribe. To subscribe again, close and reopen the browser. how to fix this? Edited December 29, 2012 by dave1234 Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 29, 2012 Share Posted December 29, 2012 Fix WHAT? Quote Link to comment Share on other sites More sharing options...
dave1234 Posted December 30, 2012 Author Share Posted December 30, 2012 user login. click Subscribe button from the article page. - database action done - correct - button text changed to Subscribed - correct & the button disabled - correct User refresh the page. click Unsubscribe button (since the user already subscribed the Unsubscribe button displayed) - no db action takes place - wrong - button text change to Subscribed - wrong & the button disabled - correct I want to fix the wrong part Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 30, 2012 Share Posted December 30, 2012 So fix it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.