Posting variable from one page to another
-
I am trying to pass a value from a select dropdown on an html form to another page after clicking a submit button. This value doesn’t need to be stored in the database, but instead used temporary to display the users choice of product data from the database on the next page. The html output of the form works as expected with the value appearing in the option value, I just can’t get it to post that value and “fetch” it from page two using POST. But If I change POST to GET. It works as expected. I’ve been told using POST is preferred, but I cant seem to get that to work?:
Form showing on page 1:
<?php echo '<form method="post" action="/page2">'; echo '<select name="selectProduct">'; echo '<option value="" disabled selected>--select--</option>'; foreach ( $getInfo as $product ) { echo '<option value="' . esc_html( $product->id ) . '">'.esc_html($product->product).'</option>'; } echo '</select>'; echo '<div class="btnWrapper">'; echo '<input class="btn border-width-0 btn-text-skin btn-color-jevc btn-square btn-icon-left adduserBtn" type="submit" name="btnSubmit" value="View specs">'; echo '</div>'; echo '</form>';
Output on page 2:
<?php // ... $selectedProduct = $_POST['selectProduct']; echo '<div><b>YOU SELECTED:</b>' . esc_html( $selectedProduct ) .'</div>';
When doing var_dump($_POST); on page2, I get an
empty array(0){}
And a php error when posting:
error when it is posting:WordPress database error:
Unknown column ‘selectProduct’ in ‘field list’ for query UPDATE
myDBtable
SET selectProduct= ’39’ WHERE id= 39Where am I going wrong?
- The topic ‘Posting variable from one page to another’ is closed to new replies.