Skip to content
Advertisement

How to submit a POST using tag?

I realize we need forms to submit a POST or perhaps with the help of a button. However, how do we do it using tags? Example code:

<?php
    $myfile = fopen("pictures.txt", "r") or die("Unable to open file!");
    while(!feof($myfile)){
      $pic_name= fgets($myfile);
      echo '<div class="grid-item">';
      echo '<a href="redirect.php"><img src="' . $pic_name . '.jpg"></a>';
      echo '</div>';
    }
?>

I’m trying use PHP to read a text file for a number of variables (names of each picture that I’ve saved). From the text file, this PHP will then convert the variables into multiple images (for each variables). Upon clicking the image, this should send the name of the picture to the next PHP site so the picture is displayed in full screen. Assume this is some kind of photo library thing that I’m trying to do. I’ve tried searching elsewhere but couldn’t get an answer for this.

Advertisement

Answer

you can use get method instead for sending data for eg. “form.php?name1=value1&name2=value2”

<?php
    $myfile = fopen("pictures.txt", "r") or die("Unable to open file!");
    while(!feof($myfile)){
      $pic_name= fgets($myfile);
      echo '<div class="grid-item">';
      echo '<a href="redirect.php/?pic_name=".$pic_name.><img src="' . $pic_name . '.jpg"></a>';
      echo '</div>';
    }
?>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement