


在一个php中,我定义了两个表单,当第一个表单提交后,生成了第二个表单,提交第二个表单后,就取不到第一个表单的数据了,该怎么办?
表单 php 提交 传递 数据
在一个php中,我定义了两个表单,当第一个表单提交后,生成了第二个表单,提交第二个表单后,就取不到第一个表单的数据了,该怎么办?//第一个表单
echo "";//第二个表单
var_dump($m);
?>
提交第二次后就得不到$m了,该怎么做才能将$m传递到最后呢?
本人新手,不懂得cookie、session。谢谢了!
回复讨论(解决方案)
这个最合理的做法就是用session或cookie保存前一次的提交,不懂的话就干脆以此为契机,学吧
这个最合理的做法就是用session或cookie保存前一次的提交,不懂的话就干脆以此为契机,学吧
恩,我临时学了一下,我的做法是两个表单分别放在两个php文件中,然后在第二个php中写了setcookie("m1",$m,time()+3600);
$m2=$_COOKIE["m1"];
然后我就用m2这个变量当做m的值,但是当我准备生成第三个表单的时候,怎么取到m?我觉得php跳转到下一个网页后就得不到前一个php的值了。如果用xml可以解决这种问题吗?
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
我也有这么想,但是不会隐藏变量啊,希望有代码参考一下,谢谢!
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
他这种需求我很久以前遇到过,就是做问卷调查时一道题一页??回答后才出现下一个问题,最初也是逐个做hidden传下去的,后来发觉十几道题就嫌麻烦了,用session反而简单多了
cookie我也觉得麻烦,如果用cookie就干脆做“假提交”,一次把题都发过去,用js把后面的题隐藏,逐个显示,到最后一题才一并提交
session的缺点是有时效性,需要在一定时间有动作才不会丢失值
cookie的缺点是客户端可以造假
在
间加入 php 代码foreach($_POST as $k=>$v) echo "";
怎么会麻烦呢?使用了 session 的表单页,无论怎么设置,“回退”的表现都不尽人意
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
我也有这么想,但是不会隐藏变量啊,希望有代码参考一下,谢谢!
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
他这种需求我很久以前遇到过,就是做问卷调查时一道题一页??回答后才出现下一个问题,最初也是逐个做hidden传下去的,后来发觉十几道题就嫌麻烦了,用session反而简单多了
cookie我也觉得麻烦,如果用cookie就干脆做“假提交”,一次把题都发过去,用js把后面的题隐藏,逐个显示,到最后一题才一并提交
session的缺点是有时效性,需要在一定时间有动作才不会丢失值
cookie的缺点是客户端可以造假
不是吧,我生成的表单是根据上一个表单提交数据才能用的,没有输出上限,hidden不行。
一样的,js也能根据“提交”内容生成控件,只是你不熟悉而已
实在搞不定就按#6老徐的方法写,这个思路最简单
我个人对数组相对熟悉些,所以习惯用session记录,懒得每次都对前面提交的数据再遍历一次
你可以这么的。两方式
一种方式就是分两页面:第一步提交后,到第二步的时候读取出来。
两步在一个页面:先用js隐藏第二步,ajax提交,那么再第二步也能获取第一步的值。
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
恩,我觉得这个方法最方便,但是没有出结果,你看看我的代码好吗?
这是第二个php:
foreach($_POST as $k=>$v)
{
echo "";
}
var_dump($m);
echo "
?>
这是第三个php:
foreach($_POST as $k=>$v)
{
echo "";
}
$n;
for($i=1;$i {
$h="n".$i;
$n[]=$_POST["$h"];
}
var_dump($n);
?>
跳转到第三个php输出的是null,网址上也仅仅跟着n1、n2、n3...的值,没有出现m,怎么回事呢?
一样的,js也能根据“提交”内容生成控件,只是你不熟悉而已
实在搞不定就按#6老徐的方法写,这个思路最简单
我个人对数组相对熟悉些,所以习惯用session记录,懒得每次都对前面提交的数据再遍历一次
谢谢你!但是我用6#上面的代码还是出不来结果,怎么回事?
放在

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











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.
