向表中添加单选按钮时查询不完整

时间:2017-09-13 08:55:05

标签: php html mysql

我正在尝试在我的PHP文件中创建一个“编辑记录”功能,您可以使用单选按钮编辑行。

我的桌子“书”里面有15条记录。它工作得很好但是当我在我的数据库中添加一行时,它会出现故障并显示:

  1. 包含不完整数据的表格。
  2. 没有按钮。
  3. 500服务器错误(很少)。
  4. 我是PHP新手,并且自学有关函数和语法。任何帮助将不胜感激:)

    这是我的PHP代码:

    <?php
    include 'config.php';
    
    session_start();
    
    $sql = "SELECT * from book";
    $result = mysqli_query($db, $sql);
    $count = mysqli_num_rows($result);
    
    if($count == 0){
        $error = "There is no books in the list";
    
    }
    
    <html>
    <body>
    <form method="post" action="editinfo.php">
    
        <table border="1" style="width:80%" align="center">
            <tr>
                <th>Edit</th>
                <th>ISBN</th>
                <th>Title of the book</th>
                <th>Cost</th>
                <th>Copies</th>
                <th>Edition</th>
                <th>Publisher</th>
                <th>Copy Year</th>
                <th>Shelf Number</th>
                <th>Subject</th>
    
            </tr>
            <?php while ($row = mysqli_fetch_array($result)) {
    
                $ISBN = $row['ISBN'];
                $Title = $row['Title'];
                $Cost = $row['Cost'];
                $Copies = $row['Copies'];
                $Edition = $row['Edition'];
                $Publisher = $row['Publisher'];
                $CopyYr = $row['CopyYr'];
                $Shelf = $row['ShelfNo'];
                $Subject = $row['SubName'];
    
                ?>
                <tr>
                    <td><input name="editradio" type="radio" value="<?php echo $ISBN; ?>" checked></td>
                    <td><?php echo $ISBN; ?></td>
                    <td><?php echo $Title; ?></td>
                    <td><?php echo $Cost; ?></td>
                    <td><?php echo $Copies; ?></td>
                    <td><?php echo $Edition; ?></td>
                    <td><?php echo $Publisher; ?></td>
                    <td><?php echo $CopyYr; ?></td>
                    <td><?php echo $Shelf; ?></td>
                    <td><?php echo $Subject; ?></td>
                </tr>
    
                <?php
            }
            ?>
        </table>
        <br>
        <table align="center" style="width:20%">
            <tr>
                <th><input type="submit" name="editinfo" value="Edit Selected"></th>
    </form>
    <form action="bookslist.php" method="post">
        <th><input type="submit" value="Back"/></th>
    </form>
    </tr>
    </table>
    <br>
    </body>
    </html>
    

    SQL Dump:

    -- --------------------------------------------------------
    
    --
    -- Table structure for table `book`
    --
    
    CREATE TABLE `book` (
      `ISBN` varchar(14) NOT NULL,
      `Title` varchar(50) NOT NULL,
      `Cost` decimal(5,2) NOT NULL,
      `Copies` int(10) NOT NULL,
      `Edition` int(15) NOT NULL,
      `Publisher` varchar(30) NOT NULL,
      `CopyYr` int(8) NOT NULL,
      `ShelfNo` int(11) NOT NULL,
      `SubName` varchar(50) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `book`
    --
    
    INSERT INTO `book` (`ISBN`, `Title`, `Cost`, `Copies`, `Edition`, `Publisher`, `CopyYr`, `ShelfNo`, `SubName`) VALUES
    ('0123704901', 'Computer Architecture: A Quantitative Approach', '24.95', 10, 4, 'Morgan Kaufmann', 2006, 11, 'ICT'),
    ('0123944244', 'Digital Design and Computer Architecture', '52.57', 10, 2, 'Morgan Kaufmann', 2012, 11, 'ICT'),
    ('0124077269', 'Computer Organization and Design', '75.74', 10, 5, 'Morgan Kaufmann', 2013, 13, 'ICT'),
    ('0205973361', 'Psychology', '158.53', 10, 4, 'Pearson', 2014, 14, ''),
    ('0321696867', 'University Physics with Modern Physics', '225.76', 10, 13, 'Addison-Wesley', 2011, 12, 'Science'),
    ('0321740904', 'Physics for Scientists and Engineers: A Strategic ', '228.16', 10, 3, 'Addison-Wesley', 2012, 15, 'Science'),
    ('0321884078', 'Thomas'' Calculus: Early Transcendentals', '198.89', 10, 13, 'Pearson', 2013, 12, 'Mathematics'),
    ('0470879521', 'Physics', '209.38', 10, 9, 'John Wiley and Sons', 2012, 11, 'Science'),
    ('0596802358', 'Data Analysis with Open Source Tools', '26.69', 10, 1, 'O''Reilly Media', 2010, 14, 'ICT'),
    ('099040207X', 'SQL Database for Beginners', '22.49', 10, 1, 'LearnToProgram, Incorporated ', 2014, 15, 'ICT'),
    ('1285057090', 'Calculus', '245.84', 10, 10, 'Cengage Learning', 2013, 13, 'Mathematics'),
    ('1429261781', 'Psychology', '152.54', 10, 10, 'Worth Publishers', 2011, 14, ''),
    ('1449600069', 'The Essentials of Computer Organization and Archit', '215.95', 10, 3, 'Jones & Bartlett Learning', 2010, 11, 'ICT'),
    ('1452257876', 'Qualitative Data Analysis: A Methods Sourcebook', '72.42', 10, 3, 'SAGE Publications, Inc', 2013, 12, 'ICT'),
    ('1590597699', 'Beginning Database Design: From Novice to Professi', '25.83', 10, 1, 'Apress', 2007, 15, 'ICT');
    
    -- --------------------------------------------------------
    

0 个答案:

没有答案