i'm trying to delete a row from database and i`m using the following code. When i submit the page reloads and if i check the db the row is still there. No error, no nothing. What can i do to solve this?
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);
}
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);
query_mysql?
Use this for your 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);
}
}
You should be using mysqli instead though.
Use this instead of the $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);
To get the numrows use this:
$numrows = $result->num_rows;
For a fetch_array:
while($row = $result->fetch_array()){
$var= $row['field'];
}
UPDATE: Add error_reporting(E_ALL ^ E_NOTICE);
to the top of php script.