【发布时间】:2017-05-12 10:33:14
【问题描述】:
我有一个包含 3 个字段的 html 论坛 Naam Achternaam 电子邮件
用户填写论坛点击提交后,会调用一个名为action_page.php的php脚本。
Taht 脚本应该将给定的信息从 html 论坛发回屏幕。
此时它只返回 3 个 NULL 值
纳姆: 阿赫特纳姆: 电子邮件: 这是html代码
我怎样才能让 PHP 脚本从 html 页面获取填写的字段,然后在屏幕上显示。
<?php
// what post fields?
$fields = array(
'Naam' => $Naam,
'Achternaam' => $Achternaam,
'Email' => $Email,
);
// build the urlencoded data
$postvars = http_build_query($fields);
// open connection
$ch = curl_init();
// set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
// execute post
$result = curl_exec($ch);
// close connection
curl_close($ch);
?>
这是php代码
html页面有3个字段
<html>
<body>
<form action="/action_page.php" method="post">
Naam: <input type="text"name="Namm"><br>
Achternaam: <input type="text" name="Achternaam"><br>
Email: <input type="text" name="Email"><br>
<td><input type='submit' name='post' value='post'></td>
<td><input type='reset' name='Rest' value='Reset'></td>
</form>
</body>
</html>
但在我点击 op sumbit 后,action_page 返回一个空白页,或者对于每个填充的字段,它在屏幕上回显 NULL。
我想要做的是一个 php 页面,它从 html 页面打印 3 个填充字段,应该将它们发布到 php 页面,以便可以将它们打印到屏幕上。
我在这里做错了什么还是在代码中的某个地方输入错误?
【问题讨论】:
-
它们在 post 数组中
-
你为什么要使用 CURL 来做这么简单的例程?!?