我想在我的表更新記錄,但我不知道在那裏我缺少提我的索引中的代碼。我確信我的連接是正確的,儘管它應該獲取索引。我已經完成了連接表的插入功能,一切正常。PHP/SQL更新表
這是我update.php
<?php
$connect = mysqli_connect("localhost", "root", "", "produktai");
{
$sql = "UPDATE dazai SET sandely='" . $_POST['sandely'] ."' WHERE id='" . $_POST['id'] ."'";
if(!mysqli_query($connect,$sql))
{
echo "pakeista";
}
else {
echo "nepakeista" . mysqli_error($connect);
}
}
header("refresh:10; url=Dazai.php");
?>
好了,我修改了我的main.php這個。我得到這個錯誤
Array([sandely] => 0 [Keisti] => Keisti)什麼可能是錯的。 0變化到任何數字我插嘴說。
<div class="prekiu_lentele">
<table class="lenetele_prekems">
<form action="update.php" method="post">
<tr>
<th>ID</th>
<th width="30%">Prekes pavadinimas</th>
<th>Gamintojas</th>
<th>Spalva</th>
<th>Kiekis</th>
<th>Blizgumas</th>
<th width="10%">Kaina</th>
<th>Kategorija</th>
<th width="20%">Kiekis sandelyje</th>
<th>Ištrinti</th>
<th width="20%">Pakeisti</th>
</tr>
</div>
<?php
$query = "SELECT * FROM dazai ORDER BY id ASC";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['pavad'];?></td>
<td><?php echo $row['Gamintojas'];?></td>
<td><?php echo $row['Spalva'];?></td>
<td><?php echo $row['Kiekis'];?></td>
<td><?php echo $row['Blizgumas'];?></td>
<td><?php echo $row['Kaina'];?>€</td>
<td><?php echo $row['Kategorija'];?></td>
<td><input type="text" style="width: 50px; margin-right:10px;" name="sandely" value="<?php echo $row['sandely'];?> "</td>
<td><a href="delete.php?recordID=<?php echo $row['id'];?>">X</a>
<td><input type="submit" name="Keisti" value="Keisti" /></td>
</tr>
</div>
</form>
更新查詢中的邏輯沒有意義 – Akintunde007
首先使用print_r檢查您在POST數組中獲得的內容,您可以繼續進一步操作。據「好嘛知道什麼可用數據的過程。我相信你一定會通過urself輕鬆地修復錯誤。...... –
」陣列()「我沒有收到任何那裏。 – deividas