找不到对象,功能显示()

时间:2014-06-03 19:34:03

标签: php html

在跟随另一个堆栈溢出问题后,我在此处找不到对象。有什么建议?我试图这样做,当你按提交时,重复PHP代码(最终它也会添加信息)。

html代码:

<form method="post" action="display()">
    <div class="form-group">    
    <input type="text" class="form-control" placeholder="Enter Text" name="caseName"/>
    <button type="submit" class="btn btn-default">Submit</button>
</form>

PHP代码:

function    display()
{
$con=mysqli_connect("localhost","root","xxx","xxx");
//    Check    connection
if    (mysqli_connect_errno())    {
echo    "Failed    to    connect    to    MySQL:    "    .    mysqli_connect_error();
}
$result    =    mysqli_query($con,"SELECT    *    FROM    caseStudies");
$row    =    mysqli_fetch_array($result);
for($i    =    0;    $i    <    1;    $i++)    {
echo    "<div    class='case'    id='case$i'>";
echo    "<div    class='row'>";
echo    "<div    class='header'>";
echo    '<h4>'    .    $row['caseName']    .    '</h4>';
echo    "</div>";
echo    "</div>";
echo    "<div    class='row'>";
echo    "<div    class='caseimg'>";
echo    '<img    src="'    .    $row['caseImage']    .    '"    class="Responsive    image"/>';
echo    "</div>";
echo    "<div    class='caseimg'>";
echo    '<img    src="'    .    $row['caseImage']    .    '"    class="Responsive    image"/>';
echo    "</div>";
echo    "<div    class='caseimg'>";
echo    '<img    src="'    .    $row['caseImage']    .    '"    class="Responsive    image"/>';
echo    "</div>";
echo    "</div>";
                            $i++;
}
}
if(isset($_POST['submit']))
{
display();
}    
?>

1 个答案:

答案 0 :(得分:1)

action中的属性<form>应该是表单数据提交到的地址。它不是函数的名称。

此外,您正在测试if(isset($_POST['submit']))。这种情况永远不会成真。您的表单中没有名为submit的输入。