Jump to content

php and sql script windows/linux


adzie

Recommended Posts

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?

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();

?>

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.

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.

$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.

<?

 

 

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();

?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.