【问题标题】:PHP Function name needs to be a string [closed]PHP函数名称需要是一个字符串[关闭]
【发布时间】:2015-01-22 09:15:59
【问题描述】:

我正在尝试制作一个非常基本的 php 表单,它可以输出用户放入数据库的一些文本。查看了其他几个类似的问题以确保并且据我所知没有其他人问过这个问题。这是从 html 获取输入的 create.php。

<?php 
    include 'connection.php';  
    $firstname= $_POST('inputName'); 
    $lastname= $_POST('inputName2');
    if($_POST ['SUBMIT']) { echo "please fill out the form"; 
    header('location:     ../index.html'); 
    } else {
    mysql_query("INSERT INTO requestdata ('firstname', 'lastname') 
    VALUES ('$firstname', '$lastname')") or die(mysql_error()); 
    echo "User has been added"; header ('Location: ../index.html'); 
    } 
    ?>

这是表单的 html 代码:

<form action = "php/create.php" method = "POST">
    First Name <input type ="text" name='inputName' value=""/>
    Last Name <input type="text" name='inputName2' value=""/>
    <br />
    <input type="submit" name = "button">
</form>`

我得到的错误是:

"致命错误:函数名必须是字符串 第 8 行的 mywebsite.com/php/create.php

【问题讨论】:

  • $_POST 是一个数组,尝试使用 [] 而不是 ()。
  • header()之前不要输出任何东西。阅读手册here

标签: php html mysql forms security


【解决方案1】:

我认为您的 $_POST 变量是错误的。

请尝试使用 $_POST['inputName'] 代替 $_POST('inputName') 和 $_POST['inputName2'] 代替 $_POST('inputName2')

【讨论】:

  • 漂亮,谢谢。现在我有一个不同的错误,但我想我可以处理这个。
猜你喜欢
  • 1970-01-01
  • 2015-03-16
  • 2013-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-30
相关资源
最近更新 更多