我试图在数据库中插入特定的值(小刀和毯子),但根本没有插入到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