html:
<select>
<code> <option name="new_class_info" value="recommend">推荐</option> </code>
php:
$sql="INSERT INTO info_look (new_class) values ('$_POST[new_class_info]')";
I posted a post yesterday, thanking everyone for your help. There is another question that I didn’t think of at the time, which is that what I want to get in $_POST[new_class_info] is the value. How should I write it here? If it is written as [new_class_info.value] , doesn’t “.” in php mean +? Please answer
ps: Some friends reminded me that user input variables cannot be directly inserted into sql. Because I am a beginner and have not considered security issues here, so currently I only need to pass in the value to make my database record. Thank you everyone
html:
<select>
<code> <option name="new_class_info" value="recommend">推荐</option> </code>
php:
$sql="INSERT INTO info_look (new_class) values ('$_POST[new_class_info]')";
I posted a post yesterday, thanking everyone for your help. There is another question that I didn’t think of at the time, which is that what I want to get in $_POST[new_class_info] is the value. How should I write it here? If it is written as [new_class_info.value] , doesn’t “.” in php mean +? Please answer
ps: Some friends reminded me that user input variables cannot be directly inserted into sql. Because I am a beginner and have not considered security issues here, so currently I only need to pass in the value to make my database record. Thank you everyone
Your name
attribute should be set on the select
element. When the form is submitted, the form elements will be submitted as name-value pairs. For the select
element, the value of the name
attribute of select
is used as the name, and the value of the value
attribute of the selected option
element is used as the value.
For example
<code class="html"><select name="foo"> <option value="bar1"> <option value="bar2"> </select></code>
If you select the first option to submit, the name-value pair of foo=bar1
will be submitted.
If you use the post method to submit, you can use the $_POST
array to access it in php. For example, the form above will have the $_POST['foo']
member, and the value is 'bar1'
.
The poster above has already said it very well. I don’t know if the poster understands it. Let me add a few more words. The poster said <select>
This is included under the tag <form>
(form), < form>
The action attribute is defined to indicate where the form is to be submitted, which is your PHP. When submitting, the contents of the form form key-value pairs and are passed to your PHP. The key is the name attribute of the tag, and the value is the value attribute. So the POST passed to PHP is similar to this [' new_class_info' => 'recommend']
, so you only need to get the new_class_info item of this array. For example: $_POST['new_class_info']