简体   繁体   English

将变量从包含的html文件传递到另一个PHP脚本

[英]passing variables from included html file to another php script

1.php 1.PHP

include'form.html'

form.html form.html

<form action="email.php" method="post">
<input type="text" id="name" value="name" />
</form>

email.php email.php

<?php
$name = $_POST['name']; 
$email_message = "Name: $name ";
$sent = mail($email_to, $email_subject, $email_message); 
if($sent) {
    echo "success=yes";
} else {
    echo "success=no";
}
include('success.html');
?>

error: 错误:

Notice: Undefined index: name in C:\wamp\www\a\action.php on line 3

I also tried making them global variables in form.html but not working 我也尝试在form.html中创建全局变量但不起作用

insert name="name" input tag of the form. insert name =“name”输入表单的标签。 like this 像这样

<input type="text" id="name" value="name" name="name" />

The name attribute specifies the name of an element. name属性指定元素的名称。 The name attribute is used to reference elements in a JavaScript, or to reference form data after a form is submitted. name属性用于引用JavaScript中的元素,或在提交表单后引用表单数据。 Only form elements with a name attribute will have their values passed when submitting a form. 只有具有name属性的表单元素才会在提交表单时传递其值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM