Jump to content

$_GET variable


Schlo_50

Recommended Posts

Hey guys,

 

I have passed $_GET['clienta'] from a.php to b.php.

 

On b.php I have a drop menu which is linked to a flatfile database. I need to adapt the code below to

get the drop menu to only display the values associated with $_GET['clienta']. I have had a go but it displays all values.

 

<?php 

print "<select name=\"category\">";

$file = file("../usercats.txt");

foreach($file as $Key => $Val){

   $Data[$Key] = explode("|", $Val);
	  
     $username = trim($Data[$Key][0]);
     $catname = trim($Data[$Key][1]);
     $catid =  trim($Data[$Key][2]);

 if($_GET['clienta'] == $username) {

     print "<option value=\"$catid\">$catname</option>";

}
}
print "</select>"; 

?>

 

Thanks in advance!

Link to comment
Share on other sites

try this out:

 

<?php 
  print "<select name=\"category\">";
  $file = file("../usercats.txt");
  foreach($file as $line){
    list($username,$catname,$catid) = explode("|",$line,3);
    if($_GET['clienta'] == $username) {
      print "<option value=\"$catid\">$catname</option>";
    }
  }
  print "</select>"; 
?>

 

if that doesn't work, please post a snippet of usercats.txt

Link to comment
Share on other sites

I used your snippet but it didn't work.

 

<form name="form1" method="post" action="?id=uploadtest">
<table width="500" border="0" cellspacing="0" cellpadding="2">
  <tr>
        <td width="138" class="text"><img src="images/point.png" width="11" height="8" border="0" />Client</td>
    <td width="354" class="text">
<?php 

if(isset($_POST['submit'])) 
{
$var = $_POST['clienta'];
print $_POST['clienta'];


}

print "<select name=\"clienta\">";
$filea = file("../users.txt");

foreach($filea as $Keya => $Vala){

$Dataa[$Keya] = explode("|", $Vala);

$client = $Dataa[$Keya][0];

print "<option value=\"$client\">$client</option>";

}

print "</select>"; 

 ?></td>
  </tr>
</table>
<input name="submit" type="submit" value="submit">
</form>

 

This is the script which is meant to pass the variable, but i think this is the problem.

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.