更新数据不起作用。没有错误,但数据不会改变

时间:2013-11-06 13:39:18

标签: php

因为考虑更新数据问题,我被困了一整天。没有错误,当点击更新时,它成功但数据没有更新。 这是我的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 code

<?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>";
?>

edit.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>

2 个答案:

答案 0 :(得分:0)

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

totalitem='$totalitem,

但它应该是:

totalitem='$totalitem',

答案 1 :(得分:0)

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