peasepud Posted August 12, 2008 Share Posted August 12, 2008 Hi all, I have a website and database setup for a client, one of the admin functions is to change the status of an item, it works simply by when the user clicks a link it pulls the record, checks the current status (1 or 0) and then reverses it before rewriting it to the database. When I have checked this on two different machines at different locations it works fine, does exactly what its meant to without problem however the client cannot get it to work (we are both logging in using the same login so its not some permissions issue). They can click the link and it does take them to the php script correctly, passing over the variable but does not update the record. I set a few echo's into the code to monitor it and it does pull the record correctly, obtains the current status but then does not change the value? heres the code (I know it could probably be written better but like I say it does work for me). <?php session_start(); include('../phpfuncts.php'); logupdate(); $sql = "SELECT * FROM `table1` WHERE (`id`= '$ident')"; $result=mysql_query($sql) or die ('Query error: ' . mysql_error()); $act=mysql_result($result,0,"active"); $outact = 1; if ($act == 1) { $outact = 0; } echo $outact; $sql="UPDATE table1 SET active = '$outact' WHERE id = '$ident'"; $sqlres = mysql_query($sql); ?> <html> <head> <meta http-equiv='refresh' content='0;url=the url of the calling page'> </head></html> Any help would be appreciated, I just cannot understand how server code can work on one users machine and not another? Oh and we're both using the same browsers (in fact its been tested by both on FF, IE and Opera). Peter Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/ Share on other sites More sharing options...
revraz Posted August 12, 2008 Share Posted August 12, 2008 Try using a mysql_error after this line $sqlres = mysql_query($sql); I would also use a new variable for the 2nd query instead of re-using $sql Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-614807 Share on other sites More sharing options...
Barand Posted August 12, 2008 Share Posted August 12, 2008 I'd do it as one update query instead of a SELECT, set values, UPDATE UPDATE table1 SET active = IF(active = 1, 0, 1) WHERE id = '$ident' Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-614908 Share on other sites More sharing options...
peasepud Posted August 12, 2008 Author Share Posted August 12, 2008 I'd do it as one update query instead of a SELECT, set values, UPDATE UPDATE table1 SET active = IF(active = 1, 0, 1) WHERE id = '$ident' yep, that makes a hell of a difference to the code thank you. I havent been able to get the client to test it out yet but I still dont understand what would cause php or mySQL to not work for a particular user? Surely, its irrelevant what machine / browser its carried out on? Unlike Javascript or flash that require plug ins or scripts enabled I thought php/SQL were global? Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615046 Share on other sites More sharing options...
Barand Posted August 12, 2008 Share Posted August 12, 2008 Where is $ident being set? Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615051 Share on other sites More sharing options...
peasepud Posted August 12, 2008 Author Share Posted August 12, 2008 ident is passed through the URL, the code in question is in a file called active_status.php and is being passed as >>> http://www.thesitesurl.com/admin/active_status.php?ident=107 Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615057 Share on other sites More sharing options...
Barand Posted August 12, 2008 Share Posted August 12, 2008 Then you need to set it explicitly with $ident = $_GET['ident']; http://uk2.php.net/manual/en/security.globals.php Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615080 Share on other sites More sharing options...
peasepud Posted August 12, 2008 Author Share Posted August 12, 2008 Then you need to set it explicitly with $ident = $_GET['ident']; http://uk2.php.net/manual/en/security.globals.php I agree that the code may not be the most secure etc but again, surely if that was the problem then it wouldnt work for any users? at the end of the day register_globals and the security implications are related to the site and not the user? Or am I missing something fundamental thats going to send me scurrying to rewrite dozens of sites? Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615083 Share on other sites More sharing options...
PFMaBiSmAd Posted August 12, 2008 Share Posted August 12, 2008 Echo out the query string to see what it actually contains. Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615095 Share on other sites More sharing options...
peasepud Posted August 12, 2008 Author Share Posted August 12, 2008 Earlier on I echoed the $ident field and the user informed me that it was correctly displaying the number expected (in the test we were doing 107) so I know its a) going to the correct php script and, b) passing the variable through correctly. so somewhere between that and carrying out the actual update its dropping out but not for me or another user thats tested it. Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615106 Share on other sites More sharing options...
Barand Posted August 12, 2008 Share Posted August 12, 2008 if register_globals is ON on one machine it will work, but if the other has register_globals OFF then it won't work. With "$ident = $_GET['ident'];" it will work on both. Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615152 Share on other sites More sharing options...
peasepud Posted August 13, 2008 Author Share Posted August 13, 2008 if register_globals is ON on one machine it will work, but if the other has register_globals OFF then it won't work. With "$ident = $_GET['ident'];" it will work on both. Ok I'll add that in but I didnt believe register_globals was a user specific variable, you set it on the server using php.ini and (I thought) that was it????? Surely if it was user specific then users could override the setting themselves making it highly unstable and unsecure? Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615460 Share on other sites More sharing options...
JonnoTheDev Posted August 13, 2008 Share Posted August 13, 2008 This is also a bad idea: <meta http-equiv='refresh' content='0;url=the url of the calling page'> You should use a 301 redirect with a header header("Location:calling-page.php"); Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615469 Share on other sites More sharing options...
revraz Posted August 13, 2008 Share Posted August 13, 2008 You are referring to Servers, he is referring to end users. if register_globals is ON on one machine it will work, but if the other has register_globals OFF then it won't work. With "$ident = $_GET['ident'];" it will work on both. Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-615534 Share on other sites More sharing options...
peasepud Posted August 14, 2008 Author Share Posted August 14, 2008 You are referring to Servers, he is referring to end users. if register_globals is ON on one machine it will work, but if the other has register_globals OFF then it won't work. With "$ident = $_GET['ident'];" it will work on both. I think yes, that maybe I havent made myself clear. This code is running on one domain on one server. Myself and the client are both accessing the same page and doing exactly the same thing yet for one of us it works while the other it doesnt. I agree all the things said previously such as the very much reduced code, the inclusion of $_GET and even the 301 redirect but they are all incidental to the actual question of how one occurrence of php/mySQL code can work for one user but not another. Quote Link to comment https://forums.phpfreaks.com/topic/119350-simple-update-works-on-one-pc-but-not-another/#findComment-616102 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.