$_SERVER['PHP_SELF'] and variables in same form

Hi All,

I’ve got a login page that has a form action of $_SERVER[‘PHP_SELF’], so if the password and username are correct, it just goes to the same page (but shows different content).

The page with the form is Downloads_login.php, and I’ve passed a variable with the url to this page:
http://localhost…/Downloads_login.php?client_id=1

I can get to it no problem, but only BEFORE submitting the form. How do I get the variable to carry on to the rest of the page?

I’ve tried hidden and normal textfields and then posted the variable, but I still can’t get it working.

Here is the page:


<html>
<head><title>Your Downloads</title></head>
<body bgcolor=#FFFFFF>

<?php
$client = $_GET['client_id'];
?>

<div align=center>
  <form name="form1" method="post" action="">
    <input type="hidden" name="client_txt" value="<?php echo "$client" ?>">
  </form>
  <TABLE WIDTH=500 BORDER=0 CELLPADDING=0 CELLSPACING=0>
	<TR>
		
      <TD> <IMG SRC='../../Images/header_01.gif' WIDTH=245 HEIGHT=51 ALT=''></TD>
		<TD>
			<IMG SRC='../../Images/header_02.gif' WIDTH=255 HEIGHT=51 ALT=''></TD>
	</TR>
	<TR>
		<TD>
			<IMG SRC='../../Images/header_03.gif' WIDTH=245 HEIGHT=54 ALT=''></TD>
		<TD>
			<IMG SRC='../../Images/header_04.gif' WIDTH=255 HEIGHT=54 ALT=''></TD>
	</TR>
	<tr>
      <td colspan=2>
        <p><b><font face='Arial, Helvetica, sans-serif'>&nbsp;<br>
          Downloads<br>
          &nbsp; </font></b></p>
      </td></tr>

<?php

// Define your username and password
$username = 'user';
$password = 'password';

if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {

?>
		<tr><td colspan=2><form name='form' method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
		<p><font face='Arial, Helvetica, sans-serif' size='-1'>Please enter your 
        Username and Password to view your Downloads</font></p>
      <table border='0' cellpadding='5' cellspacing='0'>
        <tr> 
          <td><font face='Arial, Helvetica, sans-serif' size='-1'><label for='txtUsername'>Username</label> 
            </font></td>
          <td><font face='Arial, Helvetica, sans-serif' size='-1'> 
            <input type='text' name='txtUsername' />
            </font></td>
        </tr>
        <tr> 
          <td><font face='Arial, Helvetica, sans-serif' size='-1'><label for='txtpassword'>Password</label> 
            </font></td>
          <td><font face='Arial, Helvetica, sans-serif' size='-1'> 
            <input type='password' name='txtPassword' />
            </font></td>
        </tr>
      </table>
          <p><font face='Arial, Helvetica, sans-serif' size='-1'> 
            <input type='submit' name='Submit' value='Login' />
            </font></p>
          <p><font face='Arial, Helvetica, sans-serif' size='-1'><b><a href='../index.php'>back 
            to clients options</a></b></font> </p>
</form>
</td></tr>
</TABLE>
</div>

<?php
}
else 
{
?>

<tr>
      <td colspan=2> 
        <p><b><font face="Arial, Helvetica, sans-serif" size="-1"><br>
          Windows:</font></b><font face="Arial, Helvetica, sans-serif" size="-1"> 
          right click the link and choose &quot;Save Target As&quot;<br>
          <b>Mac:</b> ctrl click and choose &quot;Download Link to Disk&quot;</font></p>
        <p>
          <?php
        
require '../../include.php';

$client_field = $_POST['client_txt'];

mysql_connect($DBhost,$DBuser,$DBpass);
mysql_select_db($DBName);

$query  = "SELECT * FROM itl_client_uploads WHERE client_id = '$client_field' ORDER BY upload_name DESC";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) 
    {
        $upload_name = $row['upload_name'];
		
		echo "<font face='Arial, Helvetica, sans-serif' size='-1'><a href='../Uploads/$upload_name'>$upload_name</a></font><br>";

	}
?>
        </p>
        <p><font face='Arial, Helvetica, sans-serif' size='-1'><b><a href='../index.php'>back 
        to clients options</a></b></font></p></td>
    </tr>
</TABLE>
</div>


<?php
}
?>
</body>
</html>

Thanks for your time
C

action="" in the form or a hidden element.

On the page that is recieving the id you need to do this:
<?php
if (isset($_GET[‘client_id’])) {
$client = $_GET[‘client_id’];
}else{
$client = false; // or some other false value
}
?>

Some suggestions… You have it a bit wordy. You only need one form and some variable that holds the error message. So when the page is submitted, rather than a long selection of form/error messages, just have one form, with an if statement that checks if there was an error message. Make sense?

Thanks Marble,

I gave it a go with isset and slimming it to one form, but I still get $client = false (I also echoed “Client is not set” to confirm that I was getting a result from the code).

Like I said in my first post, the variable is being sent in the url and I can retrieve it before submitting the form, but not after.

Is there a way to append the variables to the $_SERVER[‘PHP_SELF’]; form action?

THanks for your time already,
C

Did you put the variable in the action of the form?

Example:
action="<?php echo “somepage.php?id=”.$id; ?>"

So that $id variable (lets give it 3) will be passed to itself when you submit the form in a url like this:
somepage.php?id=3

That’s how I pass the variable to the page to begin with - then you have to login to retrieve the page. My form action is: action=’<?php echo $_SERVER[‘PHP_SELF’]; ?>
so how can I append “?id=$id” to this action?

Form variables.

try doing it like this action=’?id=$id’

That basicly will do the same as $_SERVER[‘PHP_SELF’] but with the id :slight_smile: