在php中输入标签和表单标签

时间:2015-11-01 16:11:25

标签: php mysql

好的,伙计们,我是PHP的新手。我在添加"编辑"时遇到问题。按钮作为第4列的第四个元素(Action),它是th。我需要在每个书名上添加一个“编辑”按钮,并将用户带到“编辑”页面,以便他们可以编辑书籍信息。 我不知道接下来该做什么。我不知道如何添加按钮,同时通过POST传递编辑请求。我应该改变什么?如何在php中嵌入html

是的,我正在使用XAMPP和记事本++

感谢。

<?php
include('databaseConnection.php');
?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="./css/librarySystem.css">
<title> Book List </title>
</head>

<div id="booklist_container">

    <table id="booklist_table">
        <?php

                $select_all_books = "SELECT * FROM booklist";
                $result = mysql_query($select_all_books);

                echo "<tr>";
                                echo "<th>" ."Title". "</th>" ;   
                                echo "<th>" ."Author". "</th>" ;
                                echo "<th>" ."ISBN" . "</th>" ;
                                echo "<th>" ."Action". "</th>";
                echo "</tr>";

                echo  "<form method="POST" action="edit.php">" ;

                    while($row = mysql_fetch_array($result))
                    {
                        $authorVar = $row['Author'];  
                        $titleVar = $row['Title'];
                        $ISBN = $row['ISBN'];

                        echo "<tr>";
                                        echo "<td>" . $titleVar. "</td>";   
                                        echo "<td>" . $authorVar. "</td>";
                                        echo "<td>" . $ISBN . "</td>";
                                            echo"<input type="button" value="Edit Info">"  ;

                        echo "</tr>"; 
                    } // end of while loop

                echo  "</form>" ;
        ?>

    </table>
</div>

</html>

2 个答案:

答案 0 :(得分:1)

执行按钮时出现语法错误。 做点什么

echo '<input type="button" value="Edit Info">';

用单引号替换外部双引号。

答案 1 :(得分:1)

form循环外部删除while标记,并尝试使用循环体:

$authorVar = $row['Author'];  
$titleVar = $row['Title'];
$ISBN = $row['ISBN'];

echo "<form method='POST' action='edit.php'>";
echo "<tr>";
echo "<td>" . $titleVar. "</td>";   
echo "<td>" . $authorVar. "</td>";
echo "<td>" . $ISBN . "</td>";
echo "<td>";
echo "<input type='submit' value='Edit Info'>";
echo "</td>";
echo "</tr>";
echo "<input type='hidden' name='ISBN' value='" . $ISBN . "'>"; 
echo "</form>" ;

我使用引号修复了问题,并为每个使用隐藏input提交(唯一?)ISBN号的图书条目设置了单独的表单。您可以使用此ISBN ID生成edit.php文件以匹配所选书籍。请注意,我还将input按钮从button类型更改为类型submit,以便它实际提交表单。另请注意,此按钮现在位于td标记内,以便正确呈现。

相关问题