致命错误:函数名称必须是第12行中的字符串

时间:2017-09-27 09:33:49

标签: php

已编辑:This is the error I got.

    $categoryName = $_POST['category_name'] ;
    $categoryDesc = $_POST['category_desc'] ;

    $sql = "INSERT INTO category (category_title, category_desc) VALUES ('$categoryName','$categoryDesc')";

    if (mysqli_query($con,$sql))
    {
         echo 'Inserted successfully';
    }
    else
    {
         echo 'Inserted Failed';
    }
    mysqli_close($con);

 ?>

我得到的错误是致命错误:函数名称必须是第12行中的字符串

第12行:$categoryName = $_POST['category_name'] ;

[EDITED] dbconnect.php(我不确定我是对还是错,因为我使用的是虚拟主机,这就是为什么我的服务器名是我的虚拟主机名)

<?php
$servername = "wp-one";
$username = "root";
$password = "";
$dbName = "personality_test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbName);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

?>

html代码

<div class="col-lg-6">
                                <form role="form" action="../controller/AddCategory&Question.php?create=true" method="post">
                                    <div class="form-group">
                                        <label>Category Name</label>
                                        <input class="form-control" type="text" placeholder="CategoryName" name="category_name" />
                                    </div>
                                    <div class="form-group">
                                        <label>Category Description</label>
                                        <input class="form-control" type="text" placeholder="CategoryDesc" name="category_desc" />
                                    </div>
                                    <div class="form-group input_fields_wrap">
                                        <button class="add_field_button btn btn-default" style="margin-bottom:10px;">Add New Question</button>
                                        <div class="form-group">
                                            <div class="row">
                                                    <div class="col-lg-2"><input type="text" placeholder="Number" class="form-control" name="criteria[]"></div>
                                                    <div class="col-lg-5"><input type="text" placeholder="Question" class="form-control" name="grade[]"></div>
                                            </div>

                                        </div>
                                    </div>
                                    <button type="submit" class="btn btn-default">Submit</button>
                                    <button type="reset" class="btn btn-default">Reset</button>

请帮助我,非常感谢你

2 个答案:

答案 0 :(得分:0)

$conn = new mysqli(...);

因此您必须使用$conn代替$con

if (mysqli_query($conn,$sql))
    {
         echo 'Inserted successfully';
    }
    else
    {
         echo 'Inserted Failed';
    }
    mysqli_close($conn);

答案 1 :(得分:-1)

数据库中 category_title 的数据类型是什么?

您的连接错误

// Create connection
$conn = new mysqli($servername, $username, $password, $dbName);

您使用 $ conn ,在插入文件中,您使用 $ can 而不是$ conn ......