■ Instance learning PHP form processing articles

zhaozj2021-02-11  181

Title: ■ Example Learning PHP Form Processing Preparation before learning:

If you want to learn PHP, of course, you can't install PHP, so if you are a first study, please read the article of the Network Academy: PHP4.03 installed under Linux PHP4.04 under Win98 PHP4.04 under English Win2000 Installation If you can't find the installer, please download: PHP4.04Beta Win32 installer php4.03 source PHP3.0.16 Win32 installer php3.0.16 source OK! There should be no need to stop us from learning, let 'S go! Before learning, let' s first on the basics of forms. If you are very familiar with HTML, you can skip this part and learn directly. Therefore, the name of the form is a tool for collecting data using the web page. For example, if you want to engage in a mass investigation online, it must be less than you use him. Below I briefly introduce the basic knowledge of the form, please check the HTML manual on your details. The use of the form is actually very simple. Let's take a look at the example below:

Name: single selection: I am very stupid I am very stupid I am It is a silly multi-item selection: I like to play blue ball I like to swim I like dancing I like to climb the mountain

Name: Single Selection: I am stupid, I am very stupid, I am a stupid number of choices: I like to play blueball, I like to swim, I like to dance, I like to climb, how is it? do you understand? The upper part is the HTML source code for the form, and the lower part is the form of the browser in the browser. Sign indicates that the form ends when a form is started, and the form ends when the flag . Processing the program of this form, pointing out with the action attribute in the Form flag. Here is , $ PHP_SELF is a global variable in PHP, used to save the file name of the current execution PHP program, The meaning is the current PHP The program is handled. Then what does the following Method = POST mean? In fact, the form has two methods from the browser to the server. GET and POST. GET method Package the data package in the environment variable query_string to the server as part of the entire overall as the URL. POST is a lot similar to get the same thing. Different places is that it is separated to deliver data to the script. Your script gets these data through standard input. Query_String environment variable will no longer set. So POST has better security, especially If you have a lot of data in your form. When you use get, this server assigns variable query_string to all form data, but this variable can be stored. In other words, if you have a lot of data but you use Get, you will lose a lot of data. If you use POST, you can use data as much as possible because these data never assigned to a variable. In addition, there is also a benefit using the POST transfer data. It doesn't expose the data you transmitted to the browser's address bar like Get, such as the following: form.php? Name = Genius & Pwd = 123456, understand? So use POST to make people feel at all. (Editor Note: Due to the compatibility of the database, "$" in the above source code is changed to the corresponding symbol of the half-width character in the actual application. If there is any inconvenience, please forgive.) Continue our learning, in the process of establishing a form, you usually only use two signs, one is what is said before; form> logo, there is also; input> logo, don't look at it, the form Various small controls are created by it. The type of input method can be defined by means of the INPUT logo, which is TEXT, Password, Radio, Checkbox, Submit, Reset, Image, File, Hidden, and Button. Below is a brief description of these input types:

Text generates a simple single-line text input field, in order to get multi-line text, use the simple single line text input field like the textArea> flag Password and Text, but not displaying the input content Radio on the screen to generate open and closed small radio Buttons, multiple options can be used with checkbox or; select> flag Submit generates the button RESET for the submission to the form handler to reset all input methods to null values ​​or defaults image to turn the submission button to The graphics, this value is consistent with the submission button, just when the graph is selected, the mouse position X, Y coordinate also sends it to the form handler Button generating button that does not perform specific interaction with the script Now we already know how to generate a small control, then these How to pass the data entered in the control to our program? There is a Name attribute in the Input flag to name the value to the input value, for example: name = "first". After defining, if you want to access this data, you can use it with Global. If you want to define data defaults, you can use the value attribute definition, such as the value of the above programs = "I am very stupid" is defined a default value, let's take a look at an instance of a single-choice: Input Type = radio name = " First "value =" I am very stupid "> I am very stupid; input type = radio name =" first "value =" I am very stupid "> I am very stupid; input type = radio name =" first "value =" I am just A fool "> I am just a stupid, can you see the basic usage of Name, Value? what? I still don't understand .......... (地 地 倒 地 地 ...) OK, our form is simply talking about it, let's start to enter the topic ----- PHP processing form With PHP to handle form data It is really a very simple thing. If you have a better than you eat, you will use a chopstick when you eat. It is very natural, there is nothing to pay special attention. Old look, everyone starts learning to take a look at the following code. The above is a very similar php example of the table, because the program is relatively simple, so there is no annotation. Everyone can copy this code before watching the program. Let's take a look at the actual effect first, so there is an intuitive impression. (Editor Note: Due to the compatibility of the database, "$" in the source code in the actual application is changed to the corresponding symbol of the half-width character in the actual application in the actual application. If you have inconvenience, please forgive.

questionnaire; / title> <meta http-equiv = "content-type" content = "text / html; charSet = GB2312"> </ head> <body bgcolor = "# ffffffff "> <? php function display_form () {global $ PHP_SELF;?> <form action =" <? PHP Echo $ PHP_SELF;?> "Method = Post> Name: <nput type = text name =" name "> <br > Single option: <input type = Radio name = "first" value = "I am stupid"> I am very stupid <input type = radio name = "first" value = "I am very stupid"> I am very stupid <input type = Radio name = "first" value = "I am just a stupid"> I am just a stupid; Br> Multi-selection: <input type = checkbox name = "second []" value = "I like to play blue ball "> I like to play blue ball <input type = checkbox name =" second [] "value =" I like to swim "> I like to swim <input type = checkbox name =" second [] "value =" I like dancing "> I like dancing <input type = checkbox name = "second []" value = "I like climbing"> I like climbing <input type = hidden name = "stage" value = "results">; p> <input type = Submit Value = "Thank you"> / p> </ form> <? Php}?> // Program start <? Php function process_form () {global $ name; Global $ first; global $ second; if ($ first == 'I am stupid') {$ first_MESSAGE = 'You are not stupid. ';} Elseif ($ first ==' I am very stupid') {$ first_MESSAGE = 'You are smart. ';} Else {$ first_MESSAGE =' You are just like a smart person.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-4243.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="4243" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.051</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'lY5kyp_2BFRG_2FptRlpIQADCGthX9_2Bv7zIih9wCJEdrnfP4vhHazEpMKzV68CCccIRTsvBVDH49oZTBX2CALHoDFQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>