我試圖在數據庫中插入特定的值(小刀和毯子),但根本沒有插入到DB /表中。另外,我想在下面的表格中顯示插入的值,但這並不奏效。它依賴於插入它顯示在桌子上。我確定,因爲我通過phpmyAdmin插入了一個值,並將其顯示在表格中。請,我需要修復插入方面。將特定值插入數據庫並將其顯示在表格上?
插入代碼/錯誤處理
<?php
if (isset($_POST['Collect'])) {
if(($_POST['Object'])!= "knife" && ($_POST['Object'])!= "blanket")
{
echo "This isn't among the room objects.";
}else {
// this makes sure that all the uses that sign up have their own names
$sql = "SELECT id FROM objects WHERE object='".mysql_real_escape_string($_POST['Object'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
if($m_count >= "1"){
echo 'This object has already been taken.!';
} else{
$sql="INSERT INTO objects (object)
VALUES
('$_POST[Object]')";
echo "".$_POST['object']." ADDED";
}
}
}
?>
表,還要加上額外的PHP代碼
<p>
<form method="post">
</form>
Pick Object: <input name="Object" type="text" />
<input class="auto-style1" name="Collect" type="submit" value="Collect" />
</p>
<table width="50%" border="2" cellspacing="1" cellpadding="0">
<tr align="center">
<td colspan="3">Player's Object</td>
</tr>
<tr align="center">
<td>ID</td>
<td>Object</td>
</tr>
<?
$result = mysql_query("SELECT * FROM objects") or die(mysql_error());
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)) {
// Print out the contents of each row into a table?>
<tr>
<td><label for="<?php echo $row['id']; ?>"><?php
$name2=$row['id'];
echo "$name2"; ?>
</label></td>
<td><? echo $row['object'] ?></td>
</tr>
<?php }// while loop ?>
</table>
</body>
「SET field = value」語句工作得很好,實際上... – Tsadiq 2011-03-04 15:51:02
謝謝。我修正了這一點,但它仍然不起作用。請檢查錯誤處理如果問題來自 – Kelvin 2011-03-04 15:56:42