gaurav.iit Posted December 31, 2011 Share Posted December 31, 2011 i had used session_start() for using variable between php scripts...it worked fine on wamp server but when i hosted it...it isnt working.. i m not able to access the variables...wat cud be the prblm the code is quite big and distributed..so cant post it.. help plz.. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2011 Share Posted December 31, 2011 You are likely getting an error that would help pin point the cause of the problem. Add the following three lines of code, immediately after your first opening <?php tag, before any session_start statement, and see what if any errors are reported - ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(-1); Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1302930 Share on other sites More sharing options...
gaurav.iit Posted January 1, 2012 Author Share Posted January 1, 2012 its not giving any errors...actually i have a button which uses session variables to increment some values... now that i have noticed sometimes its incremented sometimes not , could it be sm prblm in the server or internet speed.. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303011 Share on other sites More sharing options...
scootstah Posted January 1, 2012 Share Posted January 1, 2012 its not giving any errors... But did you add that code and then try? Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303058 Share on other sites More sharing options...
gaurav.iit Posted January 1, 2012 Author Share Posted January 1, 2012 yes i added the code .. its not giving any errors.. its working fine when i run it on my lappy on wamp server but when hosted it isnt working .. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303096 Share on other sites More sharing options...
PFMaBiSmAd Posted January 1, 2012 Share Posted January 1, 2012 If you search the forum for the phrase - 'isn't working', you will find that means absolutely nothing to us, because we are not standing right next to you and don't know what you saw or what you expected to see. For any specific code or even one changed line in some code, there can be a dozen different symptoms, and for any symptom there can be a dozen different things that might causing that symptom. In programming, there's not a magical one to one relationship between 'isn't working' and what is causing the problem. To get help with your code, you must post enough of your code the duplicates the problem, a statement (or picture) of the actual symptoms you saw in front of you that leads you to believe that your code isn't working, and a statement of what the actual expected result should have been. If you are getting a blank page in your browser, you also need to do a 'view source' of the page and post information about what you saw in the view source. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303099 Share on other sites More sharing options...
gaurav.iit Posted January 1, 2012 Author Share Posted January 1, 2012 ok..so i have database which contains a table girls with fields Serial(int) hits(int) name(text) ...following is code for homepage <?php ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(-1); session_start(); $con = mysql_connect("localhost","gaurav",""); mysql_selectdb("website",$con); $sql = "Select COUNT(*) from girls"; $var = mysql_query($sql,$con); $count=mysql_result($var, 0); $index1 = rand(1,$count); $index2; while(1) { $index2 = rand(1,$count); if($index1 != $index2) break; } $_SESSION['index1'] = $index1; $_SESSION['index2'] = $index2; $sql = mysql_query("SELECT * FROM girls WHERE Serial=$index1"); $row = mysql_fetch_array($sql); $name1 = $row['name']; $hits1 = $row['hits']; $sql = mysql_query("SELECT * FROM girls WHERE Serial=$index2"); $row = mysql_fetch_array($sql); $name2 = $row['name']; $hits2 = $row['hits']; echo <<<ECO <html> <head> <script src="jquery.js"></script> <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function in1(){ var ajaxRequest; try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } ajaxRequest.open("GET", "girls.php", true); ajaxRequest.send(null); } function in2(){ var ajaxRequest; try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } ajaxRequest.open("GET", "girls1.php", true); ajaxRequest.send(null); } //--> </script> </head> <body > //some html code <a href="index.php" onclick="in2();"><img src="t1.png" id="t1" /></a> <a href="index.php" onclick="in1();"><img src="t2.png" id="t2" /></a> </body> </html> ECO; ?> and girls.php is <?php ini_set("display_startup_errors", "1"); ini_set("display_errors", "1"); error_reporting(-1); session_start(); $con = mysql_connect("localhost","gaurav",""); mysql_selectdb("website",$con); $myvar = $_SESSION['index1']; $sql = "UPDATE girls SET hits = hits + 1 WHERE Serial = $myvar"; mysql_query($sql,$con); ?> similarly is girls1.php ..when i click t1.png or t2.png the hits are supposed to be incremented...but its not happening so when i hosted it... Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303132 Share on other sites More sharing options...
sunfighter Posted January 2, 2012 Share Posted January 2, 2012 <a href="index.php" onclick="in2();"><img src="t1.png" id="t1" /></a> <a href="index.php" onclick="in1();"><img src="t2.png" id="t2" /></a> Should be <a href="javascript:in1();"><img src="t1.png" id="t1" /></a> <a href="javascript:in2();"><img src="t2.png" id="t2" /></a> Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303421 Share on other sites More sharing options...
scootstah Posted January 3, 2012 Share Posted January 3, 2012 <a href="index.php" onclick="in2();"><img src="t1.png" id="t1" /></a> <a href="index.php" onclick="in1();"><img src="t2.png" id="t2" /></a> Should be <a href="javascript:in1();"><img src="t1.png" id="t1" /></a> <a href="javascript:in2();"><img src="t2.png" id="t2" /></a> Actually it should be something like: <a href="girl.php?id=t1&action=increment" onclick="in1();"><img src="t1.png" id="t1" /></a> <a href="girl.php?id=t2&action=increment" onclick="in2();"><img src="t2.png" id="t2" /></a> That way it works for people without Javascript. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303535 Share on other sites More sharing options...
sandeep529 Posted January 3, 2012 Share Posted January 3, 2012 does the domain names in the url remain same between the pages. I mean does the www prefix change between pages? Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303568 Share on other sites More sharing options...
sunfighter Posted January 3, 2012 Share Posted January 3, 2012 @scootstah This is an AJAX site. It depends on javascript being turned on. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303572 Share on other sites More sharing options...
scootstah Posted January 3, 2012 Share Posted January 3, 2012 @scootstah This is an AJAX site. It depends on javascript being turned on. Just because AJAX is used doesn't mean it depends on Javascript being turned on. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303598 Share on other sites More sharing options...
trq Posted January 3, 2012 Share Posted January 3, 2012 @scootstah This is an AJAX site. It depends on javascript being turned on. Just because AJAX is used doesn't mean it depends on Javascript being turned on. Um, indeed it does. You cannot create Ajax without JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303636 Share on other sites More sharing options...
gaurav.iit Posted January 3, 2012 Author Share Posted January 3, 2012 still not working guys.. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303775 Share on other sites More sharing options...
Adam Posted January 3, 2012 Share Posted January 3, 2012 @scootstah This is an AJAX site. It depends on javascript being turned on. Just because AJAX is used doesn't mean it depends on Javascript being turned on. Um, indeed it does. You cannot create Ajax without JavaScript. I think scootstah was just trying to say that in order to use AJAX, you don't need to leave non-JS users in the lurch. still not working guys.. If you're using a shared host it's possible that they have purposefully prevented you from showing the errors. Is there an error log somewhere in the directories you have access to? It will probably be called "error_log", or postfixed with that. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303779 Share on other sites More sharing options...
sunfighter Posted January 3, 2012 Share Posted January 3, 2012 You really have no way to know if your getting to girls.php. Set up your responseText. Try something like alert(ajaxRequest.responseText); put an echo as your first line in girls.php just to see if your getting into it. Then use echos to trace what your doing especially check your variables. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303784 Share on other sites More sharing options...
scootstah Posted January 3, 2012 Share Posted January 3, 2012 @scootstah This is an AJAX site. It depends on javascript being turned on. Just because AJAX is used doesn't mean it depends on Javascript being turned on. Um, indeed it does. You cannot create Ajax without JavaScript. I think scootstah was just trying to say that in order to use AJAX, you don't need to leave non-JS users in the lurch. Indeed. AJAX is mostly used for user convenience. There's no reason you can't add regular request functionality, which my example did just that. If the Javascript didn't run they were simply linked to a page which would increase the hit. Quote Link to comment https://forums.phpfreaks.com/topic/254145-php/#findComment-1303790 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.