我试图从数据库中删除一行,而且我正在使用以下代码。当我提交页面重新加载,如果我检查数据库,行仍然存在。没有错误,没有任何错误。我该怎么做才能解决这个问题?
HTML
<div class="delete_row">
Sterge
<form method="post" action="">
*<input type="text" name="id_col" Placeholder="Id-ul coloanei"><br>
<input type="submit" name="submit1" value="Sterge">
</form>
</div>
PHP
$id_stergere=isset($_POST["id_col"]);
$submitcheck2=isset($_POST["submit1"]);
if($submitcheck2 && $id_stergere !==0 ){
$sql = "DELETE FROM evenimente WHERE ID_even=$id_stergere";
$result = query_mysql($sql);
}
答案 0 :(得分:0)
query_mysql?
将此用于您的php:
error_reporting(E_ALL ^ E_NOTICE);
if(isset($_POST['submit1'])){
$id_stergere=$_POST["id_col"];
$submitcheck2=$_POST["submit1"];
if($submitcheck2 && $id_stergere){
$sql = "DELETE FROM evenimente WHERE ID_even=$id_stergere";
$result = mysql_query($sql);
}
}
你应该使用mysqli而不是。
使用此代替$sql = and $result = :
$link = mysqli_connect("localhost","db","password","user") or die("Error " . mysqli_error($link));
$query= "DELETE FROM evenimente WHERE ID_even=$id_stergere";
$result= mysqli_query($link,$query);
要获取数字,请使用:
$numrows = $result->num_rows;
对于fetch_array:
while($row = $result->fetch_array()){
$var= $row['field'];
}
更新:将e rror_reporting(E_ALL ^ E_NOTICE);
添加到php脚本的顶部。
答案 1 :(得分:0)
if (isset($_POST["id_col"]))
$id_stergere=$_POST["id_col"];
if (isset($_POST["submit1"]))
$submitcheck2=$_POST["submit1"];
//additional check:
// if (!is_numeric($id_stergere)) die('there was a problem');
// if (!$submitcheck2) die('there was a problem');
$sql = "DELETE FROM evenimente WHERE ID_even=".$id_stergere;
$result = mysql_query($sql);