otuatail Posted January 29, 2008 Share Posted January 29, 2008 I don't know if there is a solution to this. I store details in a table of every access to a website. I don't want duiplicates if someone hits F5. In order to do this I set a session variable to detect this. I have also a problem about a variable being passed to the function to store the data. This is the first part of the code in a page. $Page = "Board"; if($_SESSION['current_page'] != "Board" && strlen($_SESSION['current_page'] > 2) StoreDataNews($Page); // Problem with passed variable $_SESSION['current_page'] = "Board"; Here the refresh should not work because the session variable is set after storage. The line StoreDataNews shuld cause the variable to be inserted into the database as it is set 3 lines higher The function in a seperate file is. function StoreDataNews($Page) { connectDB(1); $browser = $_SERVER["HTTP_USER_AGENT"]; $stamp = time(); $Date = date('Y-m-d',$stamp); $Time = date('H:i:s',$stamp); $IP = $_SERVER['REMOTE_ADDR']; $sql = "INSERT INTO `NewsLog` VALUES ('','" . $stamp . "','" . $Date . "','" . $Time . "','" .$IP . "','" . $Page . "','" . $browser . "','" . $hit . "')"; $query = mysql_query ($sql); $result = @mysql_affected_rows($sql); } The odd behaviour can be seen at entry 39, 41, 44 etc. @ http://www.des-otoole.co.uk/news/stats.php Any sugestions would be a great help. Desmond. Quote Link to comment https://forums.phpfreaks.com/topic/88414-baffled-by-variables/ Share on other sites More sharing options...
PHP Monkeh Posted January 29, 2008 Share Posted January 29, 2008 I think the problem lies in your if() statement: if($_SESSION['current_page'] != "Board" && strlen($_SESSION['current_page'] > 2) It seems like you've missed off the ) after strlen(). So it should be: if($_SESSION['current_page'] != "Board" && strlen($_SESSION['current_page']) > 2) Give that a try and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/88414-baffled-by-variables/#findComment-452479 Share on other sites More sharing options...
otuatail Posted January 29, 2008 Author Share Posted January 29, 2008 Thanks that sort of helps out but The last bit strlen() was addred to get past the first problem. Why does StoreDataNews($Page); not add $Page into the database when $Page = "Board"; is clearly set before. There are blanks in the tabel for Page $sql = "INSERT INTO `NewsLog` VALUES ('','" . $stamp . "','" . $Date . "','" . $Time . "','" .$IP . "','" . $Page . "','" . $browser . "','" . $hit . "')"; Quote Link to comment https://forums.phpfreaks.com/topic/88414-baffled-by-variables/#findComment-452495 Share on other sites More sharing options...
PHP Monkeh Posted January 29, 2008 Share Posted January 29, 2008 Ok before you do anything else add { } to your if() statement, its a lot easier to see where the statement begins and ends when they're in. As for finding out why $Page doesn't get added, do a bit of debugging first. Comment out your INSERT line and just try echo-ing $Page and see what you get. Quote Link to comment https://forums.phpfreaks.com/topic/88414-baffled-by-variables/#findComment-452559 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.