0

我被困了一整天,因为考虑更新数据问题。没有错误,点击更新时,成功但数据没有更新。这是我的 index.php

<html>
<head>
<title>Daftar Mahasiswa</title>
</head>
<body>
<?php
$sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("kuih2") or die ("Gagal membuka database.");
?>

用于查看数据的表...

<table border="5">
    <tr>
    <th>id</th>
    <th>Item</th>
    <th>Name</th>
    <th>Address</th>
    <th>Contact</th>
    <th>Total Item</th>
    <th>Total</th>
    <th colspan="3">Aksi</th>
    </tr>
    <?php
    $query = "select * from itemorder";
    $result = mysql_query($query, $sambung);
    //$no = 0;
    while ($buff = mysql_fetch_array($result)){
    //$no++;
    ?>
    <tr>
    <td><?php echo $buff['id']; ?></td>
    <td><?php echo $buff['item']; ?></td>
    <td><?php echo $buff['name']; ?></td>
    <td><?php echo $buff['address']; ?></td>
    <td><?php echo $buff['contact']; ?></td>
    <td><?php echo $buff['totalitem']; ?></td>
    <td><?php echo $buff['total']; ?></td>
    <td><a href="edit.php?id=<?php echo $buff['id']; ?>">Edit</a></td>
    <td><a href="hapus.php?id=<?php echo $buff['id']; ?>">Hapus</a></td>
    </tr>

另一个代码...

<?php
    }
    mysql_close($sambung);
    ?>
    </table>
    <p align="left"><a href="tambah.html">Tambah Data</a></p>
    </body>
    </html>

update.php 代码

<?php
include("koneksi.php");
$id = $_POST['id'];
$item = $_POST['item'];
$name = $_POST['name'];
$address = $_POST['address'];
$contact = $_POST['contact'];
$totalitem = $_POST['totalitem'];
$total = $_POST['total'];
$query = mysql_query("update itemorder set item='$item', name='$name', address='$address',contact='$contact', totalitem='$totalitem, total='$total' where id='$id'");
echo "Data Telah diupdate<br>
<a href=\"index.php\">Kembali</a>";
?>

编辑.php代码

<?php
 $sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("kuih2") or die ("Gagal membuka database.");
//$edit=mysql_query("SELECT * FROM mhs WHERE nim='$_GET[nim]'");
//$r_edit=mysql_fetch_array($edit);
$id = $_GET['id'];
$query = "select * from itemorder where id='$id'";
$result =  mysql_query($query, $sambung) or die("gagal melakukan query");
     $buff = mysql_fetch_array($result);
                 mysql_close($sambung);
?>
<html>
<head><title>Edit Data</title></head>
<body>
<form name="form1" method="post" action="update.php">
<table>
<tr>
<td>ID</td><td><input type="text" name="id" value="<?php echo $buff['id']; ?>"></td></tr>
<tr><td>Item</td><td><input type="text" name="item" value="<?php echo $buff['item']; ?>"></td></tr>
<tr><td>Name</td><td><input type="text" name="name" value="<?php echo $buff['name']; ?>"></td></tr>
<tr><td>Address</td><td><input type="text" name="address" value="<?php echo $buff['address']; ?>"></td></tr>
<tr><td>Contact</td><td><input type="text" name="contact" value="<?php echo $buff['contact']; ?>"></td></tr>
<tr><td>Total Item</td><td><input type="text" name="totalitem" value="<?php echo $buff['totalitem']; ?>"></td></tr>
<tr><td>Total</td><td><input type="text" name="total" value="<?php echo $buff['total']; ?>"></td></tr>
<tr>
<input value="Simpan" type="submit" name="submit"/>
<input type="button" value="Kembali" onClick="self.history.back()"></td></tr>
</table>
</form>
</body>
</html>
4

2 回答 2

0

你忘了一个逗号。你写了:

totalitem='$totalitem,

但应该是:

totalitem='$totalitem',
于 2013-11-06T13:42:15.517 回答
0

这只是 update.php 中的拼写错误,而不是 totalitem='$totalitem' 你有 totalitem='$totalitem....它一直在发生。希望这会有所帮助

于 2013-11-06T14:28:17.803 回答