我正在尝试从表中删除一行,但是即使按照stackoverflow上的示例进行操作,我也无法找到解决方案。 开始之前的重要事情之一是我隐藏了该URL,因此我看不到“获取URL”,即使连接也不会删除表的右行。
HTML:
<button id="{{value.username}}" type='button' type="button" ng-click="delete(value.username, $index)" class="btn btn-primary">Delete</button></td>
JS
$scope.delete = function(deletingId, index){
console.log(deletingId);
$http.get("../admin/deleted.php?username=" + deletingId)
.success(function(data){
$scope.data.splice(index, 1);
console.log('dadasdas');
})
}
PHP
$id = $_GET ['username'];
$sql = "SELECT * FROM members";
$records = mysql_query($sql);
if(isset($_GET['username'])){
$id = $_GET ['username'];
$delete = "DELETE FROM members WHERE username= '$id'";
$res = mysql_query($delete) or die ("FAILED" .mysql_error());
}
我做错了什么吗(作用域正常,php src是正确的,但是即使在php上执行echo也不能满足要求),因为我已经隐藏了url,因此无论如何都将其作为帖子发布?
预先感谢
答案 0 :(得分:1)
尝试一下(我将使用Mysqli,因为我不使用Mysql);
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password, $dbname);
$id = $_GET['username'];
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if (strtolower($id) == strtolower($row['username'])) {
$sql = "DELETE FROM users WHERE id=".row['id'];
$conn->query($sql);
}
}
} else {
echo "No accounts registered!";
}
因此,使用SQL删除内容区分大小写。因此,我希望/认为您的数据库中有一个自动增量id
。然后,这肯定会100%有效!