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?

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'";
  }

?>

Link to comment
Share on other sites

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"?>"?>

Link to comment
Share on other sites

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 ?>"?>

Link to comment
Share on other sites

<?

 

 

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

?>

Link to comment
Share on other sites

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.

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.