PHP Sending parameter to sub procedure

Hi everyone,
It seems I dont understand the mechanism of sending a parameter from one PHP procedure to another.
Here is the code of the main procedure test.php:

<!DOCTYPE html>
<html>
<head>
  <title>Update Records In MYSQL Database Using PHP</title>
</head>
<body>
  <!--connecting to database-->
  <?php
    $con = mysqli_connect('aa', 'bb', 'cc', 'dd');
    IF(!$con)
      DIE('Gevald' .MYSQLI_CONNECT_ERROR());
    $records = mysqli_query($con, "SELECT * FROM stations");
  ?>
  <table>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
      </tr>
      <?php
        while($row = mysqli_fetch_array($records))
	{
	  echo "<tr><form action = 'test.php' method = 'post'>";
	  echo "<td><input type = 'text' name = 'mkt_id' value = '".$row['id']."'></td>";
	  echo "<td><input type = 'text' name = 'mkt_name' value = '".$row['name']."'></td>";
	  echo "<td><a href='test1.php?edit_mkt=".$row['id']."'>edit</a></td>";
	  echo "</form></tr>";
	}
      ?>
    </table>
</body>		
</html> 

The sub procedure (test1.php) to accept the parameter (mkt) goes like this:

<?php
  echo $edit_task;
?>

When I run the main “test.php”, I receive an error message from test1.php that says:
“Notice: Undefined variable: edit_task in C:\xampp\htdocs\update\test1.php on line 17”
Can anyone explain me why do I get that error and how to pass the parameter from test.php to test1.php?
Thanks

test1.php is not a subprocedure. It’s a completely new request you make.

Since you call test1.php from the HTML generated by test.php, you need to pass parameters via URL. Alternately you can store data in a session and have both scripts access them.

If you’re talking about the result of this hyperlink:

echo "<td><a href='test1.php?edit_mkt=".$row['id']."'>edit</a></td>";

then you need to extract the value of the parameter you called edit_mkt in your destination code test1.php. You’ve passed it in as a URL parameter, so it will be in the $_GET array.

2 Likes

Thanks a lot droopsnoot !

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.