Jump to content

simple update, works on one PC but not another


peasepud

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?  :o

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.