Delete table record in php
up vote
0
down vote
favorite
Within the while I created the delete button:
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela2 .= '<tr>';
$tabela2 .= '<td>'.$rows_cursos['IdEstado'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['DataRequis'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela2 .= '<td><form action="./delete" method="post">';
$tabela2 .= '<input type="hidden" name="IdEstado" value="'.$rows_cursos['IdEstado'].'">';
$tabela2 .= '<button type="button" class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
$tabela2 .= '</form></td>'; //só fechando o form
$tabela2 .= '</tr>';
}
$tabela2 .= '</tr>';
$tabela2 .='</tbody>';
$tabela2 .= '</table>';
$tabela2 .= '</div>';
echo $tabela2;
The action = "./delete"
I put it this way because I'm working on wordpress and the action
of this form is equal to action = "delete.php"
.
After deleting.php I have this code:
$id = $_POST['IdEstado'];
$sql = "DELETE FROM `centrodb`.`RequisicaoLuvas` WHERE `RequisicaoLuvas`.`id` = " . $id;
mysqli_query($conn,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
$sql1 = "DELETE FROM `centrodb`.`EstadoLuvas` WHERE `EstadoLuvas`.`IdEstado` = " . $id;
mysqli_query($conn,$sql1) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
When I click the delete button it does not delete anything in the database table.
php html mysql
|
show 9 more comments
up vote
0
down vote
favorite
Within the while I created the delete button:
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela2 .= '<tr>';
$tabela2 .= '<td>'.$rows_cursos['IdEstado'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['DataRequis'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela2 .= '<td><form action="./delete" method="post">';
$tabela2 .= '<input type="hidden" name="IdEstado" value="'.$rows_cursos['IdEstado'].'">';
$tabela2 .= '<button type="button" class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
$tabela2 .= '</form></td>'; //só fechando o form
$tabela2 .= '</tr>';
}
$tabela2 .= '</tr>';
$tabela2 .='</tbody>';
$tabela2 .= '</table>';
$tabela2 .= '</div>';
echo $tabela2;
The action = "./delete"
I put it this way because I'm working on wordpress and the action
of this form is equal to action = "delete.php"
.
After deleting.php I have this code:
$id = $_POST['IdEstado'];
$sql = "DELETE FROM `centrodb`.`RequisicaoLuvas` WHERE `RequisicaoLuvas`.`id` = " . $id;
mysqli_query($conn,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
$sql1 = "DELETE FROM `centrodb`.`EstadoLuvas` WHERE `EstadoLuvas`.`IdEstado` = " . $id;
mysqli_query($conn,$sql1) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
When I click the delete button it does not delete anything in the database table.
php html mysql
what error do you get?
– Prashanth Benny
Nov 19 at 14:08
3
Your button is a button and not a type="submit".
– Demodave
Nov 19 at 14:09
@Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
– Bruno
Nov 19 at 14:09
@Demodave is going to delete.php page
– Bruno
Nov 19 at 14:11
you could use die(mysqli_error($conn)); to display the exact error
– Prashanth Benny
Nov 19 at 14:12
|
show 9 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Within the while I created the delete button:
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela2 .= '<tr>';
$tabela2 .= '<td>'.$rows_cursos['IdEstado'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['DataRequis'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela2 .= '<td><form action="./delete" method="post">';
$tabela2 .= '<input type="hidden" name="IdEstado" value="'.$rows_cursos['IdEstado'].'">';
$tabela2 .= '<button type="button" class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
$tabela2 .= '</form></td>'; //só fechando o form
$tabela2 .= '</tr>';
}
$tabela2 .= '</tr>';
$tabela2 .='</tbody>';
$tabela2 .= '</table>';
$tabela2 .= '</div>';
echo $tabela2;
The action = "./delete"
I put it this way because I'm working on wordpress and the action
of this form is equal to action = "delete.php"
.
After deleting.php I have this code:
$id = $_POST['IdEstado'];
$sql = "DELETE FROM `centrodb`.`RequisicaoLuvas` WHERE `RequisicaoLuvas`.`id` = " . $id;
mysqli_query($conn,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
$sql1 = "DELETE FROM `centrodb`.`EstadoLuvas` WHERE `EstadoLuvas`.`IdEstado` = " . $id;
mysqli_query($conn,$sql1) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
When I click the delete button it does not delete anything in the database table.
php html mysql
Within the while I created the delete button:
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela2 .= '<tr>';
$tabela2 .= '<td>'.$rows_cursos['IdEstado'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['DataRequis'].'</td>';
$tabela2 .= '<td>'.$rows_cursos['Funcionario'].'</td>';
$tabela2 .= '<td><form action="./delete" method="post">';
$tabela2 .= '<input type="hidden" name="IdEstado" value="'.$rows_cursos['IdEstado'].'">';
$tabela2 .= '<button type="button" class="btn btn-danger">Excluir</button>'; //aqui está o seu botão
$tabela2 .= '</form></td>'; //só fechando o form
$tabela2 .= '</tr>';
}
$tabela2 .= '</tr>';
$tabela2 .='</tbody>';
$tabela2 .= '</table>';
$tabela2 .= '</div>';
echo $tabela2;
The action = "./delete"
I put it this way because I'm working on wordpress and the action
of this form is equal to action = "delete.php"
.
After deleting.php I have this code:
$id = $_POST['IdEstado'];
$sql = "DELETE FROM `centrodb`.`RequisicaoLuvas` WHERE `RequisicaoLuvas`.`id` = " . $id;
mysqli_query($conn,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
$sql1 = "DELETE FROM `centrodb`.`EstadoLuvas` WHERE `EstadoLuvas`.`IdEstado` = " . $id;
mysqli_query($conn,$sql1) or die("Erro ao tentar cadastrar registro");
mysqli_close($conn);
When I click the delete button it does not delete anything in the database table.
php html mysql
php html mysql
edited Nov 19 at 14:12
asked Nov 19 at 14:06
Bruno
165
165
what error do you get?
– Prashanth Benny
Nov 19 at 14:08
3
Your button is a button and not a type="submit".
– Demodave
Nov 19 at 14:09
@Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
– Bruno
Nov 19 at 14:09
@Demodave is going to delete.php page
– Bruno
Nov 19 at 14:11
you could use die(mysqli_error($conn)); to display the exact error
– Prashanth Benny
Nov 19 at 14:12
|
show 9 more comments
what error do you get?
– Prashanth Benny
Nov 19 at 14:08
3
Your button is a button and not a type="submit".
– Demodave
Nov 19 at 14:09
@Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
– Bruno
Nov 19 at 14:09
@Demodave is going to delete.php page
– Bruno
Nov 19 at 14:11
you could use die(mysqli_error($conn)); to display the exact error
– Prashanth Benny
Nov 19 at 14:12
what error do you get?
– Prashanth Benny
Nov 19 at 14:08
what error do you get?
– Prashanth Benny
Nov 19 at 14:08
3
3
Your button is a button and not a type="submit".
– Demodave
Nov 19 at 14:09
Your button is a button and not a type="submit".
– Demodave
Nov 19 at 14:09
@Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
– Bruno
Nov 19 at 14:09
@Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
– Bruno
Nov 19 at 14:09
@Demodave is going to delete.php page
– Bruno
Nov 19 at 14:11
@Demodave is going to delete.php page
– Bruno
Nov 19 at 14:11
you could use die(mysqli_error($conn)); to display the exact error
– Prashanth Benny
Nov 19 at 14:12
you could use die(mysqli_error($conn)); to display the exact error
– Prashanth Benny
Nov 19 at 14:12
|
show 9 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php
<?php
$id = $_POST['IdEstado'];
$pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
$prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
$prepared_statement->bindParam(':id', $id);
$prepared_statement->execute();
$pdo = null;
?>
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php
<?php
$id = $_POST['IdEstado'];
$pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
$prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
$prepared_statement->bindParam(':id', $id);
$prepared_statement->execute();
$pdo = null;
?>
add a comment |
up vote
0
down vote
accepted
You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php
<?php
$id = $_POST['IdEstado'];
$pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
$prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
$prepared_statement->bindParam(':id', $id);
$prepared_statement->execute();
$pdo = null;
?>
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php
<?php
$id = $_POST['IdEstado'];
$pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
$prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
$prepared_statement->bindParam(':id', $id);
$prepared_statement->execute();
$pdo = null;
?>
You can do it easy with PDO and avoid SQL Inyection if you want to use mysqli you can do something similar. Follow this link: http://php.net/manual/es/mysqli-stmt.bind-param.php
<?php
$id = $_POST['IdEstado'];
$pdo = new PDO("mysql:host=" . $dataBaseHost . "; dbname=" . $dataBaseName . "", $dataBaseUserName, $dataBasePassword);
$prepared_statement = $pdo->prepare("DELETE FROM RequisicaoLuvas WHERE id=:id");
$prepared_statement->bindParam(':id', $id);
$prepared_statement->execute();
$pdo = null;
?>
answered Nov 19 at 14:50
manelseo
1124
1124
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376378%2fdelete-table-record-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what error do you get?
– Prashanth Benny
Nov 19 at 14:08
3
Your button is a button and not a type="submit".
– Demodave
Nov 19 at 14:09
@Prashanth Benny I am not receiving any errors, neither on the page nor in the chrome console
– Bruno
Nov 19 at 14:09
@Demodave is going to delete.php page
– Bruno
Nov 19 at 14:11
you could use die(mysqli_error($conn)); to display the exact error
– Prashanth Benny
Nov 19 at 14:12