【问题标题】:php page gives blank page or Null Value [duplicate]php页面给出空白页面或空值[重复]
【发布时间】: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 来做这么简单的例程?!?

标签: php html post


【解决方案1】:

不确定这是否是您要查找的内容,但要获取发布的值,您将使用 $_POST superglobal

$fields = array(
    'Naam' => $_POST["Naam"],
    'Achternaam' => $_POST["Achternaam"],
    'Email' => $_POST["Email"],
);

【讨论】:

  • 没有工作仍然是空白页
  • @baao 我会看看他们的&lt;input type="text"name="Namm"&gt; 并有几个原因。缺少间距和错误的名称属性。
  • @fred wat 你指的是wearg name属性吗
猜你喜欢
  • 1970-01-01
  • 2015-12-18
  • 2013-06-15
  • 2021-04-14
  • 1970-01-01
  • 2013-03-03
  • 2017-05-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多