2013-07-18 28 views
0

我的MySQL數據庫的輸入和輸出有一些小問題。問題出在我的網頁的一部分。當我通過a在我的頁面中輸入供應商的名稱時,它被記錄在MySQL數據庫中。但是,當我使用與此供應商追蹤某種信息的其他表格輸入相同的名稱時,另一個表格僅記錄供應商名稱的第一個字,例如: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> 


這是輸入數據到所述第二表,即在該表中的數據被用作用於上面所示的「選擇」標籤輸入的代碼。我的問題是,即使表2中的數據已完成(ABC Co. Ltd.),表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>"; 

?> 
+8

請顯示錶格模式和插入代碼。 – eggyal

+0

我如何在這裏顯示架構?請告訴我。謝謝 – vjrngn

+0

這不僅僅是一個SQL問題。請注意,例如,您沒有發佈SQL代碼。你基本上是要求人們調試你的整個應用程序嗎?爲了獲得這種幫助,您通常需要發佈所有相關代碼,並瞭解該應用程序的工作方式或應該如何工作以防萬一有人遇到問題。 – Paul

回答

0

的選項元素時漏掉了值屬性雙引號:

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

應該是:

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

由於supname串與引號分隔,瀏覽器只發布第一個單詞(直到第一個空格,假設下一個單詞是其他屬性)。