MySQL的记录检索只给出了每条记录中的第一个单词

时间:2013-06-14 02:46:28

标签: php mysql database record

我有一本书数据库相当简单,只有1个表有9个字段。几个字段中有多个单词,但是当我在表格中显示记录时,我只得到第一个单词。

我使用了print_r($record['title']);

进行了测试

正如您将从数据库图像中看到的那样,它会在表格外显示完整标题。我已经完成了代码,无法看到问题所在,但我知道这很有可能是一个简单的解决方案。

<?php
    include "mysqlconnect2.php";    
    mysql_select_db('MySite',$conx);    

    if (isset($_POST['update'])){
        $updateQuery = "UPDATE books SET id='$_POST[id]', section='$_POST[section]', topic='$_POST[topic]', subtopic='$_POST[subtopic]', title='$_POST[title]', isbn13='$_POST[isbn13]', isbn10='$_POST[isbn10]', cdincluded='$_POST[cdincluded]', notes='$_POST[notes]' WHERE id='$_POST[id]'";

        mysql_query($updateQuery, $conx);


    };



    $sql = "SELECT `id`,`section`,`topic`,`subtopic`,`title`,`isbn13`,`isbn10`,`cdincluded`,`notes` FROM books";
    $mydata = mysql_query($sql,$conx);

    echo "<table border=1>
    <tr>
    <th>id</th>
    <th>Section</th>
    <th>Topic</th>
    <th>Subtopic</th>
    <th>Title</th>
    <th>Isbn13</th>
    <th>Isbn10</th>
    <th>Cd Included</th>
    <th>Notes</th>
    <th>Update</th>
    </tr>";

    while ($record = mysql_fetch_array($mydata)){
        print_r($record['title']);
        echo "<form action='books3.php' method='post'>";
        echo "<tr>";
        echo "<td>" . "<input type='text' name='id' disabled value=" . $record['id']  . "> </td>";
        echo "<td>" . "<input type='text' name='section' value=" . $record['section'] . "> </td>";
        echo "<td>" . "<input type='text' name='topic' value=" . $record['topic'] . "> </td>"; 
        echo "<td>" . "<input type='text' name='subtopic' value=" . $record['subtopic'] . "> </td>"; 
        echo "<td>" . "<input type='text' name='title' value=" . $record['title']  . "> </td>";
        echo "<td>" . "<input type='text' name='isbn13' value=" . $record['isbn13']  . "> </td>";
        echo "<td>" . "<input type='text' name='isbn10' value=" . $record['isbn10']  . "> </td>";
        echo "<td>" . "<input type='text' name='cdincluded' value=" . $record['cdincluded']  . "> </td>";
        echo "<td>". "<input type='text' name='notes' value=" . $record['notes']   . "> </td>";
        echo "<td>" . "<input type='submit' name='update' value='Update'>";
        echo "</td>";
        echo "</tr>";
        echo "</form>"; 
    }
    echo "</table>";
    mysql_close($conx);

?>

Screenshot of DB and output

提前致谢

1 个答案:

答案 0 :(得分:2)

您的问题在于您如何创建HTML:

您的代码提供了类似的内容:

<td><input type='text' name='title' disabled value=Several words in a title> </td>

但你需要这个:

 <td><input type='text' name='title' disabled value='Several words in a title'> </td>

(请注意标题周围的引号。)

在您的值周围添加额外的引号。

echo "<td><input type='text' name='title' value='" . $record['title']  . "'> </td>";