html - Delete Button in PHP isn't Working -


i'm trying add php button on site, doesn't seem working.

the delete php script is;

if(isset($_post["delete"])) {      $delquery = "delete emails id=$_post["delete"]";     mysqli_query($connection, $delquery);  } 

and form looks on same file;

<form action="email-response.php" method="post">   <input type="hidden" name="hidden" value="<?php echo $row['id']; ?>">   <input type="submit" name="delete" value="delete"> </form>  

however whenever clicked delete button nothing happening.

in relation reply saying $connection function wrong, here function working fetching information posts.

define("db_server", "myservername"); define("db_user", "myusername"); //username define("db_pass", "mypassword"); //password define("db_name", "mydbname"); // database name  $connection = mysqli_connect(db_server, db_user, db_pass, db_name);  if(mysqli_connect_errno()) {     die("database connection failed: " .         mysqli_connect_error() .         " (" . mysqli_connect_errno() . ")"     ); } else {     echo "connected"; } 

the element wish delete named hidden , not delete.

  • that submit button named (delete).

change query this:

if(isset($_post["delete"]) && !empty($_post["hidden"])){    $id = mysqli_real_escape_string($connection, $_post["hidden"]); }  $delquery = "delete emails id='$id'";  mysqli_query($connection, $delquery) or die(mysqli_error($connection));  if(mysqli_affected_rows($connection)){   echo "it successful."; } 
  • isset($_post["delete"]) check if submit button clicked.

  • using mysqli_affected_rows() show if query successful.
    function i've grown use more often.


add error reporting top of file(s) find errors.

<?php  error_reporting(e_all); ini_set('display_errors', 1);  // rest of code 

sidenote: error reporting should done in staging, , never production.


sidenote: using present method, leaves open sql injection.

use mysqli prepared statements, or pdo prepared statements, they're safer.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -