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; ?> 
3
  • 1
    What do you get in var_dump($_POST); ? Commented Dec 2, 2019 at 13:47
  • 2
    This line looks suspicious: <input type= 'hidden' name='test' value=<?php echo $title;?> /> Where are the quotes around $title? Commented Dec 2, 2019 at 13:47
  • var_dump($_POST); gives array(1) { ["test"]=> string(5) " , with quotes around $title the result is the same.. array(1) { ["test"]=> string(5) " Commented Dec 2, 2019 at 13:50

1 Answer 1

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;\"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.