-3
我想更新數據庫中的記錄並在表中顯示,但是此代碼無法理解發生了什麼問題。請通知我,謝謝。親愛的,我非常感謝你。我怎麼能糾正它?它是如何可能出現和問題是什麼在此代碼如何在PHP中更新記錄,sqli
<?php
include("connection.php");
$edit_rec = $_GET['edit'];
$query= "SELECT * from card_rec where id='$edit_rec'";
$run = mysqli_query($con,$query);
$row = mysqli_fetch_row($run);
if ($_POST)
{
$name = $_POST['name'];
$fname = $_POST['fname'];
$school = $_POST['school'];
$address = $_POST['address'];
$contact = $_POST['contact'];
$id = $_POST['id'];
$query1="UPDATE card_rec SET name='$name', fname='$fname', school='$school',address='$address',contact= '$contact' WHERE id='$id'";
if ($query1) {
echo "<script>alert('Record Update'); window.location = 'card_rec.php' </script>";
}
else
{
echo "not update";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Update</title>
</head>
<body>
<form method="post">
<input type="hidden" name="id" value="<?php echo $row[0] ?>"><br>
<input type="text" name="name" value="<?php echo $row[1] ?>"><br>
<input type="text" name="fname" value="<?php echo $row[2] ?>"><br>
<input type="text" name="school" value="<?php echo $row[3] ?>"><br>
<input type="text" name="address" value="<?php echo $row[4] ?>"><br>
<input type="text" name="contact" value="<?php echo $row[5] ?>"><br>
<input type="submit" name=" submit">
</form>
</body>
</html>
你的腳本是[SQL注入攻擊]的風險(http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)看一看發生了什麼[小Bobby表](http://bobby-tables.com/)即使[如果你逃避投入,它不安全!](http://stackoverflow.com/questions/5741187/sql-injection-使用[prepared-parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)。 –
你不知道什麼是錯的,因爲你不檢查你的代碼中的錯誤。永遠不要假設代碼總是完美無缺地工作。使用['mysqli_error()'](http://php.net/manual/en/mysqli.error.php)從數據庫中獲取詳細的錯誤信息。 –
你從未執行過查詢或將db連接傳遞給它,所以你的UPDATE從未發生過。 –