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
https://forums.phpfreaks.com/topic/91258-_get-variable/
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
https://forums.phpfreaks.com/topic/91258-_get-variable/#findComment-467664
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
https://forums.phpfreaks.com/topic/91258-_get-variable/#findComment-467677
Share on other sites

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.