为什么我的“提交”按钮不适用于我在PHP中制作的此表单?

时间:2018-11-12 12:51:06

标签: php html

这真的让我感到难过,因为它应该相对简单一些。我试图在我在PHP中回显的表的中间创建一个表单,只剩下一个提交按钮。此表单中的“提交”按钮的名称是从与我有正常连接的数据库中提取的。

我已经过全面测试,可以确认数据来自数据库。我在页面中也有其他两个类似的表单,它们工作正常,并且可以正常工作。当我将此特殊表格放在那些工作表格旁边时,它可以正常工作。除此之外,我无法在其他任何地方使用此表格。

这是我破碎表格的代码以及上下文:

function buildTables($thecategory = "staff")
{
    include "db.php";
    setlocale(LC_MONETARY, 'en_GB');        

    $stmt = $mysql->query($_SESSION['query']);
    $customercount = 0;
    $totalpoints = 0;
    $paythismonth = 0;

    while ($row = $stmt->fetch()) 
    {
        echo'<table><tr><article style="line-height: 0.5em; padding-bottom:2em; background-color:FF7070; color: white; height: 20em; width: 100em; margin-left: 14em">
        <div style="display: table-row; color: white">
        <div style="display: table-cell; padding-left: 2em; padding-top: 2em">
        <p style="font-weight: bold; font-size: 1.8em">'.$row['Forename'].' '.$row['Surname'].'</p>
        <p>ID: '.$row['ID'].'</p>
        <p>Forename: '.$row['Forename'].'</p>
        <p>Surname: '.$row['Surname'].'</p>';

        if ($thecategory == "staff")
        {
            echo  '</div><div style="display: table-cell; padding-left: 20em; padding-top: 2em"><br><br><p style="font-weight: bold; font-size: 1.2em">Emergency Contact</p>
            <p>Forename: '.$row['Emergency Forename'].'</p>
            <p>Surname : '.$row['Emergency Surname'].'</p>
            <p>Address Line 1 : '.$row['Emergency Address Line 1'].'</p>
            <p>Address Line 2 : '.$row['Emergency Address Line 2'].'</p>
            <p>City: '.$row['Emergency City'].'</p>
            <p>Country: '.$row['Emergency Country'].'</p>
            <p>Postcode: '.$row['Emergency Postcode'].'</p>

            #BROKEN FORM HERE
            <form action="editstaff.php" method="post">
            <input type="submit" value="Edit staff member" style="font-size: 1.2em" name="'.$row['ID'].'" /></form></div>'; 
        }

这是表中我可以可以使用表格的其他地方。

    if ($thecategory == "customers")
    {
        $customercount+=1;
        echo '</div><div style="display: table-cell; padding-left: 20em; padding-top: 2em"><br><br>
        <p>Points: '.$row['Points'].'</p>';
        $totalpoints += $row['Points'];
        $averagepoints = $totalpoints / $customercount;
        echo '
        <form action="editcustomer.php" method="post">
        <input type="submit" value="Edit customer" style="font-size: 1.2em" name="'.$row['ID'].'"></form>
        <form action="removecustomer.php" method="post">
        <input type="submit" value="Remove customer" style="font-size: 1.2em" name="'.$row['ID'].'"></form></div>';
    }

只需确认一下,这种确切的代码在我网站的其他位置完全可以正常工作,但在这里却不能。有什么想法吗?

编辑:这是页面的整个HTML输出:

<head>
    <title>Manager</title>
    <link rel="stylesheet" type="text/css" href="gamerz-Music.css">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <font face="Arial Black", Gadget, sans-serif></font>
</head>


<style>

body {
    background-image: url("blank.png")
}
</style>


<div class="header">
    <img src="logo.png" alt="">

    <div class="topnav">
        <a class="active" href="#Home">Home</a> 
        <a href="/2018-ac32006/team7/games.php">Games</a>
        <a href="/2018-ac32006/team7/music.php">Music</a>
        <a href="/2018-ac32006/team7/tvandmovies.php">TV/FILM</a>
        <div class="search-container">
            <form action="/action_page.php">
                <input type="text" placeholder="Search.." name="search">
                <button type="submit"><i class="fa fa-search"></i></button>
            </form>
        </div>
    </div>
</div>

<br><br><br>


<div class="Pop" style="width: 1em; position: fixed; margin-top: 4em">
    <form method = "post">
        <input type="submit" name="staff" value="View all staff" style="font-size: 1.2em; background-color: pink; height: 3em; width: 10em">
        <input type="submit" name="customers" value="View all customers" style="font-size: 1.2em; background-color: pink; height: 3em; width: 10em; margin-top: 1em">
    <form>
</div>

<br>CATEGORY = staff<br><table><tr><article style="line-height: 0.5em; padding-bottom:2em; background-color:FF7070; color: white; height: 20em; width: 100em; margin-left: 14em">
            <div style="display: table-row; color: white">
            <div style="display: table-cell; padding-left: 2em; padding-top: 2em">
            <p style="font-weight: bold; font-size: 1.8em">William Shatner</p>
            <p>ID: DI3446</p>
            <p>Forename: William</p>
            <p>Surname: Shatner</p><p>Role: Technician</p>
                <p>Date of Birth: 1931-03-22</p>
                <p>Date Employed: 2015-02-04</p>
                <p>NI Number: OO502044N</p>
                <p>Hourly Salary: £10.20</p>
                <p>Hours This Month: 40</p><p>Pay so far this month: £408.00</p>
                <p>Contact Number: 07987345197</p></div><div style="display: table-cell; padding-left: 20em; padding-top: 2em"><br><br><p style="font-weight: bold; font-size: 1.2em">Contact Details</p>
            <p>Address Line 1 : 48 Victoria Road</p>
            <p>Address Line 2 : </p>
            <p>City : Bath</p>
            <p>Country: UK</p>
            <p>Postcode: BA56 2SY</p></div><div style="display: table-cell; padding-left: 20em; padding-top: 2em"><br><br><p style="font-weight: bold; font-size: 1.2em">Emergency Contact</p>
                <p>Forename: Leonard</p>
                <p>Surname : Nimoy</p>
                <p>Address Line 1 : 98 East Street</p>
                <p>Address Line 2 : </p>
                <p>City: Cambridge</p>
                <p>Country: UK</p>
                <p>Postcode: CM6 0WT</p>
                <form method="POST" action="editstaff.php">
                <input type="hidden" name="ID" value="DI3446">
                <input type="submit" name="submit" value="submit"></form></div></article></tr></table><br>
</body>

<div class="footer">
        <a href="Sam">Facebook Page</a>
        <br>
        <a href="Location"> Dundee DD1 4LA</a>
</div>

1 个答案:

答案 0 :(得分:0)

问题很简单。为了提交表单,您必须将按钮放在<form></form>标签之间,如下所示:

<form method="POST" action="your_file.php">
    <input type="hidden" name="ID" value=".$row['ID'].">
    <input type="submit" name="submit" value="submit">
</form>

通过放置类似以下标记的更好方法:

 <a href="your_file.php?ID=".$row['ID']."&action=edit">edit</a>
 <a href="your_file.php?ID=".$row['ID']."&action=remove">remove</a>