Passing variables from a HTML form to PHP

Jim Reamer

One of the submissions in my form is Choose Your Opponent. It has 425 options based on a data query. The form element is a select list name = 'opponent'. Here is the line that produces the the User sees.

while($opponent = mysqli_fetch_assoc($oresults)) {              
    echo '<option value = "'. $opponent['id'] .'">'. $opponent['school'] .'</option>';          
}

The user sees 'school', but it passes 'id' to the PHP. Is there a way to send both the value and what the option user sees to the PHP?

Only the opponent's 'id' is going into the data table, but I want also send 'school' back to the user saying, "Your stats vs. 'school' has been submitted".

I know I can produce it with another query, but I'd rather not.

BillJustin

you can put both the id and the school in the option value as a string then convert it into an array

echo '<option value = "'. $opponent['id'] .','. $opponent['school'] .'">'. $opponent['school'] .'</option>';

you will probably receive a string of something like: 'id,school' next, convert this string into an array. refer to code below

$string = 'id,school'     // this is your select option value
$array = explode(',', $string)

above code will give you $array = [ 'id', 'school' ] which you can now output to your page.

echo 'Your stats '. $array[0] .' vs school '. $array[1] .' has been submitted';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From

Passing a Image from a html form to Go

From Dev

echo a html page and entering values into a form from php variables

From Dev

HTML Form not passing data to php processor

From Dev

Passing integer variables into SQL statement from another form

From Dev

Passing variables with additional parameters from PHP to Python

From Dev

NodeJS passing parameter from HTML form

From Dev

Error passing php variables to another page via form data

From Dev

Passing variables from PHP to AJAX success function

From Dev

Passing javascript valiables from HTML form to PayPal

From Dev

Passing variables from Javascript to HTML

From Dev

HTML not passing content to PHP contact form

From Dev

Passing data from Angular form to PHP

From Dev

Is it possible passing html elements attributes with a PHP form?

From Dev

Passing variables into pdf from html

From Dev

Passing data from `HTML` Login form to `PHP` for data retrivel from `MySQL' database

From Dev

Passing variables from javascript via ajax to php

From Dev

Form not passing variables php

From Dev

Passing variables from one form to another in vb6

From Dev

Block content for passing variables from python to HTML

From Dev

Passing variables from javascript to php file

From Dev

Passing user input from HTML form through a Python function to define variables in Flask

From Dev

Passing in context variables to form

From Dev

Passing variables to html from Python

From Dev

PHP Form not passing variables to second form

From Dev

Passing in variables from JS object into an html button

From Dev

PHP script to write to new file using variables from HTML form

From Dev

Passing variables in php as paramters through form action on submit

From Dev

Passing data from an html form into a Javascript object

From Dev

Passing values from HTML form to Python Flask

Related Related

  1. 1

    Passing a Image from a html form to Go

  2. 2

    echo a html page and entering values into a form from php variables

  3. 3

    HTML Form not passing data to php processor

  4. 4

    Passing integer variables into SQL statement from another form

  5. 5

    Passing variables with additional parameters from PHP to Python

  6. 6

    NodeJS passing parameter from HTML form

  7. 7

    Error passing php variables to another page via form data

  8. 8

    Passing variables from PHP to AJAX success function

  9. 9

    Passing javascript valiables from HTML form to PayPal

  10. 10

    Passing variables from Javascript to HTML

  11. 11

    HTML not passing content to PHP contact form

  12. 12

    Passing data from Angular form to PHP

  13. 13

    Is it possible passing html elements attributes with a PHP form?

  14. 14

    Passing variables into pdf from html

  15. 15

    Passing data from `HTML` Login form to `PHP` for data retrivel from `MySQL' database

  16. 16

    Passing variables from javascript via ajax to php

  17. 17

    Form not passing variables php

  18. 18

    Passing variables from one form to another in vb6

  19. 19

    Block content for passing variables from python to HTML

  20. 20

    Passing variables from javascript to php file

  21. 21

    Passing user input from HTML form through a Python function to define variables in Flask

  22. 22

    Passing in context variables to form

  23. 23

    Passing variables to html from Python

  24. 24

    PHP Form not passing variables to second form

  25. 25

    Passing in variables from JS object into an html button

  26. 26

    PHP script to write to new file using variables from HTML form

  27. 27

    Passing variables in php as paramters through form action on submit

  28. 28

    Passing data from an html form into a Javascript object

  29. 29

    Passing values from HTML form to Python Flask

HotTag

Archive