# $\_SERVER\['PHP\_SELF'\] and variables in same form

**URL:** <https://forum.kirupa.com/t/-server-php-self-and-variables-in-same-form/60483>\
**Category:** programming\
**Created:** [August 10, 2004, 7:24am UTC](https://forum.kirupa.com/t/-server-php-self-and-variables-in-same-form/60483 "2004-08-10T07:24:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carixpig](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/carixpig/32/304_2.png) [@Carixpig](https://forum.kirupa.com/u/Carixpig)\
**Post date:** [August 10, 2004, 7:24am UTC](https://forum.kirupa.com/t/-server-php-self-and-variables-in-same-form/60483/1 "2004-08-10T07:24:55Z")

</div>

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](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:

```php

<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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 10, 2004, 3:22pm UTC](https://forum.kirupa.com/t/-server-php-self-and-variables-in-same-form/60483/2 "2004-08-10T15:22:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 11, 2004, 11:38pm UTC](https://forum.kirupa.com/t/-server-php-self-and-variables-in-same-form/60483/3 "2004-08-11T23:38:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2004, 12:41am UTC](https://forum.kirupa.com/t/-server-php-self-and-variables-in-same-form/60483/4 "2004-08-12T00:41:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2004, 5:29am UTC](https://forum.kirupa.com/t/-server-php-self-and-variables-in-same-form/60483/5 "2004-08-12T05:29:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2004, 6:07am UTC](https://forum.kirupa.com/t/-server-php-self-and-variables-in-same-form/60483/6 "2004-08-12T06:07:02Z")

</div>

Form variables.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 18, 2004, 1:37am UTC](https://forum.kirupa.com/t/-server-php-self-and-variables-in-same-form/60483/7 "2004-08-18T01:37:43Z")

</div>

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

That basicly will do the same as $\_SERVER[‘PHP\_SELF’] but with the id 🙂
