以下代碼能夠從數據庫中刪除行,但無法插入。這是爲什麼?
<?php
mysql_connect("localhost","formuser","password") or die(mysql_error());
mysql_select_db("formpractice") or die(mysql_error());
$name = $_POST['name'];
$address = $_POST['address'];
// Add into DB Query
$insert = "INSERT INTO Users(name, address) VALUES ('$name', '$address')";
$insert_result = mysql_query($insert);
// Delete from DB Query
$delete = "DELETE FROM Users WHERE name = '$name' OR address = '$address'";
$delete_result = mysql_query($delete);
if(isset($_REQUEST['submit'])) {
if ($insert_result) {
echo "Success";
} else {
echo "Failed to submit";
}
echo 'Submit Request';
} else if (isset($_REQUEST['delete'])) {
if ($delete_result) {
echo "Deleted";
} else {
echo "Failed to submit";
}
}
?>
您刪除記錄您插入笑 – Sam
你是如何加載此PHP代碼? HTML表單?捲曲? AJAX? –
你知道'mysql_query'運行查詢,對吧? –