PHP4 Practical Application Experience (8)_PHP Tutorial
Author: Sun Movement
You may have noticed that in all the examples we have given you so far, we have given you two pages - a simple HTML page with a form, and another A PHP script used to process form input and produce corresponding output. However, PHP provides an elegant way to combine those two pages through the $submit variable
As you already know, once a form is submitted to the PHP script, all the form variables become PHP variables. Now, in addition to user-defined variables, a variable named $submit is created every time you click the "SUBMIT" button on the form. Therefore, by testing whether this variable exists, a clever programmer can use only one page to both initialize the form and produce post-submit output.
Let us show you a demonstration - we use one page to implement the fortune cookie example above, including the initial selection date page and the subsequent fortune cookie page. Let's assume that the new PHP file is also called "cookie.php"
---------------------------------- --------------------------------------------------
< ?
if (!$submit)
{
// If $submit does not exist, it implies that the form has not been submitted yet
// So the first page is displayed
?>
< html>
< head>
< style type="text/css">
td {font-family: Arial ;}
< /style>
< /head>
< body>
< font face="Arial" size="+2">
The Amazing Fortune Cookie Generator
< /font>
< form method="GET" action="cookie.php">
< table cellspacing="5" cellpadding="5" border="0">
< tr>
< td align="center">
Pick a day
< /td>
< td align="right">
< select name="day">
< option value="Monday">Monday
< option value="Tuesday" >Tuesday
< option value="Wednesday">Wednesday
< option value="Thursday">Thursday
< option value="Friday">Friday
< option value="Saturday">Saturday
< option value="Sunday">Sunday
< /select>
< /td>
< /tr>
< tr>
< tr>
< td colspan="2" align="center">
< input type="submit" name="submit" value= "Hit me!">
< /td>
< /tr>
< /table>
< /form>
< /body>
< /html>
< ?
}
else
{
// If $submit does exist, the form has been Submitted
// So use the switch() function to process
// The decision variable here is the date selected by the user
switch ($day)
{
// The first case
case "Monday":
$fortune = "When you can find a way to make everything complicated and exciting, don't make it simple and effective";
break;
// The first case
case "Tuesday":
$fortune = "Life is a bridge in the game? - You must have used some kind of trick. ";
break;
case "Wednesday":
$fortune = "What can make a sane person live in this world and never go crazy? ";
break;
case "Thursday":
$fortune = "Don't be crazy, be fun";
break;
case "Friday":
$fortune = "Just follow the times and go with the trend. When you get promoted, you will find that type is a devil.";
break;
// If none of the above conditions are met...
default:
$fortune = "Sorry, closed on weekends";
break ;
< /head>
< body>
Here is your fortune for < ? echo $day; ?>:
< br>
< b>< ? echo $fortune; ?>< /b>
< /body>
< /html>
< ?
}
?> ;
------------------------------------------------ ----------------------------------
As you can see, the script first tests the $submit variable exists, if not found, it will assume that the form has not been submitted and display the original date selection list
Since the ACTION attribute of the < FORM> tag is set to the same PHP script, once the form is submitted, the same The script will be called to handle the form input. However, this time the $submit variable will already exist, so the original page will no longer be displayed, but the page with the fortune cookie will be displayed. > Note that in order for these to work properly, your
-------------------------------- --------------------------------------------------
< input type="submit">
---------------------------------- -----------------------------------------------
Required There is a NAME attribute assigned the value "submit"
--------------------------------- -----------------------------------------------
< input type="submit" name="submit">
-------------------------------- --------------------------------------------------------
http://www.bkjia.com/PHPjc/316001.html
www.bkjia.com
true

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

A constant is also called a variable and once defined, its value does not change during the execution of the program. Therefore, we can declare a variable as a constant referencing a fixed value. It is also called text. Constants must be defined using the Const keyword. Syntax The syntax of constants used in C programming language is as follows - consttypeVariableName; (or) consttype*VariableName; Different types of constants The different types of constants used in C programming language are as follows: Integer constants - For example: 1,0,34, 4567 Floating point constants - Example: 0.0, 156.89, 23.456 Octal and Hexadecimal constants - Example: Hex: 0x2a, 0xaa.. Octal

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

On May 17, the 2023 China International Consumer Electronics Expo kicked off at the Qingdao International Exhibition Center. With the theme of "Integrating Wisdom, Data Gathering the Future", this expo brought together more than 300 companies to showcase the latest technologies and discuss the latest technologies. Industry trends and jointly seek future development opportunities. At the exhibition, Hotspot Technology displayed a series of technological products with the themes of smart home, e-sports and outdoor camping. Among them, Li Weike’s smart AR glasses attracted the attention of many viewers with their technologically full appearance. In terms of appearance, Li Weike's AR glasses use a detachable ultra-light one-piece hyperboloid lens, which has the characteristics of anti-glare, anti-sweat, and anti-fingerprint, and can adapt to various outdoor lighting environments. The frame is made of lightweight TR90 plastic titanium material, relying on ergonomic research on Chinese head circumference big data.

If you have money and want to buy a robot, should you buy a four-legged robot? Or is it better to buy a bipedal robot? The four-legged robot is like a pet and can even be taken out for a walk; the two-legged robot is more like a partner and can do housework for you in the future. Each seems to have its own merits, is it hard to decide? As an adult, Digest’s answer is of course: Last week, at the 2022 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS2022) held in Kyoto, Japan, speakers from Worcester Polytechnic Institute (WPI) and Shanghai University of Science and Technology Researchers have proposed a new solution. Let the quadruped robot evolve into a biped robot when you want to land on all fours

1. Start the WeChat application on your mobile phone and log in to your account. 2. After entering the WeChat homepage, slide the page upwards, find [WeChat Sports] and click to open it. 3. Enter the WeChat sports interface and click to open the settings button in the upper right corner.

Zero Zero Technology, the pioneer of flying cameras, announced the launch of the Harvard flying cameras X1PRO and X1PROMAX, and launched crowdfunding on Indiegogo in the early morning of August 27, Beijing time. Within 145 minutes of being online, the crowdfunding amount exceeded one million US dollars, creating the first flying camera. New record. As the world's first and most advanced flying action cameras, these two products redefine the flying shooting experience and are especially suitable for sports enthusiasts and professional content creators. Hafu flying cameras X1PRO and X1PROMAX are portable and foldable, eliminating the need for a remote control interactive experience. X1PROMAX: 1/1.3-inch CMOS sensor, customized 7-layer lens. 8K video, 14 stops of dynamic range, 107° wide-angle field of view. Customizable ND filters. X

When choosing the lowest-end central processing unit (CPU), it's important to balance affordability with basic needs. For users using 1150 motherboards, choosing a suitable minimum configuration CPU can meet the needs of daily office work, web browsing and light entertainment. This article will recommend several suitable CPUs for you in terms of performance, price, power consumption, and scalability. Among the selections of the lowest-performance CPU, performance is an important consideration. For general office and light entertainment users, a quad-core processor is enough to meet the needs. Intel's i3 series and PentiumG series are both good choices. The i3 series has higher performance and larger cache, suitable for handling multi-tasking and multi-threaded applications. The PentiumG series is

We're excited to introduce Pingora, our new HTTP proxy built on Rust. Processing more than 1 trillion requests per day, improving performance and bringing new capabilities to Cloudflare customers while requiring only one-third of the CPU and memory resources of the original proxy infrastructure. As Cloudflare continues to expand, we have found that NGINX's processing power can no longer meet our needs. While it performed well over the years, over time we realized it had limitations in meeting the challenges at our scale. Therefore, we felt it was necessary to build some new solutions to meet our performance and functionality needs. Cloudflare customers and users use Cloudfla
