adzie Posted May 23, 2007 Share Posted May 23, 2007 I have a script php that works on a linux host but will not work on a windows 2003 host. is there much of a difference? Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 yes... to an extent... many of the things are the same... a few are different... Quote Link to comment Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 is there much of a difference? Not really. You can usually get pretty much the same environment by changing a few config options. Of course there are certain functions that are only available on *nix and vice versa. What does this code do / not do exectly? Can we see it? Quote Link to comment Share on other sites More sharing options...
chigley Posted May 23, 2007 Share Posted May 23, 2007 Does the code use any PHP addons? Quote Link to comment Share on other sites More sharing options...
adzie Posted May 23, 2007 Author Share Posted May 23, 2007 just a simple web form to edit and insert new records as i say this works fine on the linux but on windows just a blank screen include("connectdb.php"); $query="SELECT * FROM members WHERE RED='$RED'"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $VID=mysql_result($result,$i,"RED"); $NAME=mysql_result($result,$i,"NAME"); $PASSWORD=mysql_result($result,$i,"PASSWORD"); ?> <b><font color="#000080" face="Verdana">Test Script Form</font></b> <form action="updated.php"> <p>VID: <input type="text" name="RED" value="<? echo "$RED"?>"?><br> Name: <input type="text" name="NAME" value="<? echo "$NAME"?>"?><br> PASSWORD: <input type="text" name="PASSWORD" value="<? echo "$PASSWORD"?>"?><br> <input type="Submit" value="Update"> </p> </form> <? ++$i; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 This is simply because your Linux system has register_globals switched off. This on by default now for security reasons. You should (if possible) switch it off on your linux box, then fix your code to support it. ie; INstead of accessing form variables directly by name, you will find them in the $_POST array. (Or $_GET) in your example. eg; $RED becomes $_GET['RED'] in your current code. Quote Link to comment Share on other sites More sharing options...
adzie Posted May 23, 2007 Author Share Posted May 23, 2007 out of curiosity how can you turn this on and off? Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 i believe its in php.ini.........? Quote Link to comment Share on other sites More sharing options...
adzie Posted May 23, 2007 Author Share Posted May 23, 2007 ok i'll try that solution you suggested on a side note the script to insert a record inserts a record but with no details i've entered I guess that same problem for that? Quote Link to comment Share on other sites More sharing options...
AV1611 Posted May 23, 2007 Share Posted May 23, 2007 Globals are a bad thing from a security standpoint. when you switched them off, you broke your script now it won't run on windows or linux, the exact opposite of what you wanted. Now you have to go back and edit your code to not use globals. then it should run on both boxes. Quote Link to comment Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 More than likely. The problem is $RED does not exist with register_globals being on. However, before you go chenging anything, be aware that register_globals should be off. Its your Linux setup and your code that needs to change. Quote Link to comment Share on other sites More sharing options...
adzie Posted May 23, 2007 Author Share Posted May 23, 2007 thanks gents for the quick and informative responses, as an example though the sample script I posted here what specifics would you recommend changing? Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 $RED --> $_POST[RED]; any form directed variables, need to go through $_POST Quote Link to comment Share on other sites More sharing options...
adzie Posted May 23, 2007 Author Share Posted May 23, 2007 sorry to seem stupid i'm still learning this i was chuffed when it worked before so I change anything $red to $_GET['RED'] where would i put the $_POST? Quote Link to comment Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 $query="SELECT * FROM members WHERE RED='$_POST[RED]'"; Quote Link to comment Share on other sites More sharing options...
adzie Posted May 23, 2007 Author Share Posted May 23, 2007 at fear of seeming stupid I have changed the query string as above and edited the get bits but still nothing? Quote Link to comment Share on other sites More sharing options...
per1os Posted May 23, 2007 Share Posted May 23, 2007 $query="SELECT * FROM members WHERE RED='$_POST[RED]'"; I think you are leading him a stray here bud. Try this: <?php $query="SELECT * FROM members WHERE RED='" . $_POST['RED'] . "'"; ?> Remember to use the code tags so they can actually see what you are trying to tel them. He probably thinks he just needs the $_POST not with the red part. Quote Link to comment Share on other sites More sharing options...
taith Posted May 24, 2007 Share Posted May 24, 2007 oops... sorry... that was my bad... by the time i noticed it was wrong, it wouldnt let me modify it :'( Quote Link to comment Share on other sites More sharing options...
trq Posted May 24, 2007 Share Posted May 24, 2007 The op's form uses the get method... Id'e also recommand cleaning the variable before using it in any query. <?php if (isset($_GET['RED'])) { $red = $_GET['RED']; $query = "SELECT * FROM members WHERE RED = '$red'"; } ?> Quote Link to comment Share on other sites More sharing options...
adzie Posted May 24, 2007 Author Share Posted May 24, 2007 i'll try both later, thanks i guess these need editing $VID=mysql_result($result,$i,"RED"); $NAME=mysql_result($result,$i,"NAME"); $PASSWORD=mysql_result($result,$i,"PASSWORD"); and ="<? echo "$RED"?>"?> Quote Link to comment Share on other sites More sharing options...
trq Posted May 24, 2007 Share Posted May 24, 2007 These dont.... $VID=mysql_result($result,$i,"RED"); $NAME=mysql_result($result,$i,"NAME"); $PASSWORD=mysql_result($result,$i,"PASSWORD"); but, "<? echo "$RED"?>"?> should be... "<? echo $VID ?>"?> Quote Link to comment Share on other sites More sharing options...
adzie Posted May 24, 2007 Author Share Posted May 24, 2007 ok i have edited the file with the amendments, previousl the form was opened using this in the url bar update.php?VID=000007 but still nothing Quote Link to comment Share on other sites More sharing options...
trq Posted May 24, 2007 Share Posted May 24, 2007 Post your current code. Quote Link to comment Share on other sites More sharing options...
adzie Posted May 24, 2007 Author Share Posted May 24, 2007 <? include("connectdb.php"); if (isset($_GET['VID'])) { $red = $_GET['VID']; $query = "SELECT * FROM members WHERE VID = '$VID'"; } $i=0; while ($i < $num) { $VID=mysql_result($result,$i,"VID"); $NAME=mysql_result($result,$i,"NAME"); $PASSWORD=mysql_result($result,$i,"PASSWORD"); ?> <b><font color="#000080" face="Verdana">Test Update Form</font></b> <form action="updated.php"> <p>VID: <input type="text" name="VID" value="<? echo $VID ?>"?><br> Name: <input type="text" name="NAME" value="<? echo $NAME ?>"?><br> PASSWORD: <input type="text" name="PASSWORD" value="<? echo $PASSWORD ?>"?><br> <input type="Submit" value="Update"> </p> </form> <? ++$i; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted May 24, 2007 Share Posted May 24, 2007 You never define $num or actually execute your query. Try this... <?php include("connectdb.php"); if (isset($_GET['VID'])) { $red = $_GET['VID']; $query = "SELECT * FROM members WHERE VID = '$VID'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)) { $VID = $row["VID"]; $NAME = $row["NAME"]; $PASSWORD = $row["PASSWORD"]; ?> <font color="#000080" face="Verdana">Test Update Form</font> <form action="updated.php"> <p>VID: <input type="text" name="VID" value="<? echo $VID ?>"?> Name: <input type="text" name="NAME" value="<? echo $NAME ?>"?> PASSWORD: <input type="text" name="PASSWORD" value="<? echo $PASSWORD ?>"?> <input type="Submit" value="Update"> </p> </form> <?php } } } } ?> PS: Using caps for variable names is genrally a bad idea. CONSTANTS nromally use caps, its just good practice. PPS: Are you really expecting to recieve more than one record here? You don't need the loop otherwise. 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.