php - MySQL 的输出

标签 php html mysql forms

我的 MySQL 数据库的输入和输出有一个小问题。问题出在我网页的一个部分。当我通过 a 在页面中输入供应商名称时,它会记录在 MySQL 数据库中。但是,当我使用相同的名称作为跟踪该供应商的某些信息的另一个表单的输入时,另一个表仅记录供应商名称的第一个单词,例如:

(供应商表中的数据):名称:ABC Co. Ltd.
(使用该供应商名称提交第二次表单后的数据输出):名称:ABC

我已附上相关两个表的架构。

不幸的是,整个名称没有记录在数据库中。我希望这是清楚的。请让我知道我能做什么。提前致谢! RTGS Table:This is the second table, ie the one which takes as input only part of the name.

Supplier Table: This is the first table, the one which forms the input to the rtgs table.

以下是将数据输入到我的帖子中的第一个表的代码。此表单使用“select”标签,该标签根据第二个表中的数据库条目进行更新。

<?php
include ('navbar.php');
mysql_connect('localhost','USERNAME','PASSWORD');
mysql_select_db(rtgs);
?>
<html>
<head>

    <title>
    </title>

</head>
<body>
    <center>
    <div class="form">

            <form action="ntxn.php" method="post">

            <table>
                    <tr>
                            <td>Supplier Name:</td>


                            <td>
                                <?php                                    


                                echo "<select name='supplier'>";
                                $result = mysql_query("SELECT supname FROM supplier");
                                while ($row = mysql_fetch_assoc($result))
                                                {
              echo "<option value=" . $row['supname'].">" . $row['supname'] ."</option>";

                                                }

                                echo "</select>";                                       
                                ?>
                            </td>
<td><button><a style="text-decoration:none"href="newsup.php">Add New?</a></button></td>
                    </tr>

                    <tr>
                            <td>Bill No. :</td>
                            <td><input type ="text" name="billno"/></td>
                    </tr>

                    <tr>
                            <td>Bill Date : </td>
                            <td><input type="date" name="billdate"/></td>
                    </tr>

                    <tr>
                            <td>Bill Amount : </td>
                            <td><input type="text" name="billamt"/></td>
                    </tr>

                    <tr>
                            <td>NEFT / RTGS No. :</td>
                            <td><input type="text" name="rtgs"/></td>
                    </tr>

                    <tr>
                            <td><input type="submit" name="submite" value="Save"/></td>
                    </tr>

            </table>
    </form>
    </div>
    </center>
</body>
</html>
<小时/> <小时/>

这是向第二个表输入数据的代码,即该表中的数据用作上面所示的“select”标签的输入。我的问题是,即使表2中的数据是完整的(ABC有限公司),表1中的数据仅以ABC作为输入。希望这能让我的问题清楚。 :)

<?php

include ('navbar.php');

mysql_connect('localhost', 'USERNAME', 'PASSWORD');
mysql_select_db(rtgs);

$result = mysql_query("INSERT INTO supplier VALUES 
        (NULL,'$_POST[supname]','$_POST[add1]','$_POST[add2]','$_POST[tin]',
        '$_POST[ed]','$_POST[ph]','$_POST[email]')");


if(!$result){
    echo "Could not add entry to database" . mysql_error();
}

else
{   
    echo "<center>";
    echo "Supplier added successfully!";
    echo "<center>";
}

echo "<center>";

echo "What would you like to do next?";
echo "<br/>";
echo "<br/>";

echo "<button><a style='text-decoration:none' href=index.html>Home</a></button>";
echo "<button><a style='text-decoration:none' href=newsup.php>Add another</a>/button>";
echo "<button><a style='text-decoration:none' href=newtxn.php>New TXN</a></button>";

echo "</center>";

?>

最佳答案

选项元素的 value 属性缺少双引号:

echo "<option value=" . $row['supname'].">" . $row['supname'] ."</option>";

应该是:

echo '<option value="' . $row['supname'] . '">' . $row['supname'] . '</option>';

由于 supername 字符串没有用引号分隔,因此浏览器仅发布第一个单词(直到第一个空格,假设下一个单词是其他属性)。

关于php - MySQL 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17723138/

相关文章:

PHP计算使用变量

javascript - 可通过 Javascript 和 Php 访问的存储?

php - PHP 中的 @SET (SQL)

php - 如何根据用户互动/最感兴趣的用户对帖子进行排序

javascript - 从动态 html 导出 pdf

php - tests.php 问题 - sipp webfrontend

html - 粘性页脚弄乱了部分的高度

html - 我想要并排放置 2 个相同大小的元素 (reCaptcha)

php - 在繁忙的网站上使用单例连接到 MySql

php - 获取mysql中第三张表的数据