将变量从包含的html文件传递到另一个PHP脚本
问题描述:
1.php
include'form.html'
form.html
<form action="email.php" method="post">
<input type="text" id="name" value="name" />
</form>
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
1.php p>
include'form.html'\ n code> pre>
form.html p>
&lt; form action =“email.php”method =“post”&gt;
&lt; input type =“text”id =“name”value =“name”/>
</form>
nnemail.php p>
&lt;?php
$ name = $ _POST ['name'];
$ email_message =“姓名:$ name”;
$ sent = mail($ email_to,$ email_subject,$ email_message);
if($ sent){
echo“success = yes”;
} else {
echo“success = no”;
}
include('success.html');
?&gt;
code> pre>
错误: p>
注意:未定义的索引:C:\ wamp \ www \ a \ action.php中的名称 在第3行
code> pre>
我也尝试在form.html中创建全局变量但不能正常工作 p>
div>
答
insert name="name" input tag of the form. like this
<input type="text" id="name" value="name" name="name" />
The name attribute specifies the name of an element. The name attribute is used to reference elements in a JavaScript, or to reference form data after a form is submitted. Only form elements with a name attribute will have their values passed when submitting a form.