0

My form button not sending var via post.

I've followed the code example in the following links.

PHP Pass variable to next page

HTML form is not sending $_POST values

Send value of submit button when form gets posted

but keep getting..

Notice: Undefined index: test in /public_html/test/seats.php on line 3

or blank page when using isset.

PAGE 1

foreach($res as $row) {


  $title = $row['Title'];

  $perfDate = $row['PerfDate'];
  $perfTime = $row['PerfTime'];

   echo "<tr>";
   echo "<td>".$title."</td>";
   echo "<td>".$perfDate."</td>";
   echo "<td>".$perfTime."</td>";
   echo "<td><form action='seats.php' method='post'>
   <input type= 'hidden' name='test' value=<?php echo $title;?> /> 
   <input type='submit' value='Submit'></form></td>";

   echo "</tr>";


}

enter image description here

Ultimately I will be passing row info, to build an SQL query on the next PHP page, however at the moment I am unable to send the even just the $title.

Using the below code gives me nothing so the issue must be with my POST in page 1?

PAGE 2

<?php

$value = "";
$value = isset($_POST['test']) ? $_POST['test'] : '';
echo $value;
?>

1 Answers1

1

The problem is this line

echo "<input type= 'hidden' name='test' value=<?php echo $title;?> />"

because the php tag is already opened the above line will output the php tag as a string.

to fix this you can simply do this value=\"$title;\"

Nathan Kolpa
  • 89
  • 1
  • 11