mysqli - Delete Row from DB using PHP/MYSQL -


i trying delete data row mysql db.

below query prints result of table keywords in them. see pic see how results show up: enter image description here

i able data addkeywordtable however, can not deletion take place. here index.php page shows input button gets clicked activate deletion:

 <?php  include 'db.php';    $sql = mysqli_query($con,"select * addkeywordtable order   keyword_name asc");   print <<<here  <table id="home">  here;   while ($row = mysqli_fetch_array($sql))  {  $key = $row['keyword_name'];   print <<<here  <tr><td>  <form method="post" formenctype="multipart/form-data" formmethod="post"        value="delete"      action="deletekey.php">  <tr>  <input type="hidden" name="sel_key" value="$id">  <input type="submit" name="delete" value=" delete " id="deletekey" > $key  <hr/></tr>  </form></td></tr>      here;  }      print "</tr></table></body></html>";   ?> 

when click "delete" button, taken confirm page deletekey.php looks this:

        <?php      require 'db.php';     $sel_key = $_post[sel_key];      //sql statement select information     $sql = "select * addkeywordtable keyid = $sel_key";      //loop through record , values     while ($key = mysqli_fetch_array($result)) {     $id = $key['keyword_name'];     } // end while loop      $pagetitle = "delete keyword";      print <<<here     <div id="form1profile">     <h2>are sure want delete record?<br/>     permanently removed:</h2>      <ul>     <li>keyword category:<br/></li>     $key;     </ul>     <p><br />     <form method="post" action="reallydelete.php">     <input type="hidden" name="id" value="$id">     <input type="submit" name="reallydelete" value="confirm delete" />     <input type="button" name="cancel" value="cancel"     onclick="location.href='addprofile.php'" /></a>     </p></form></div>     here;     // close else      ?> 

and after confirm deletion, taken confirm page: "reallydelete.php". page having trouble with. reason, variable not display contents of row/keyword name.

my db has 2 columns in it: keyid , keyword_name

here delete confirmation page. how pass $id db delete keyword/record.

  <?php       include 'db.php';    $id = $_post[id];   $sql = "select * addkeywordtable keyword_name = '$id'";    while ($row = mysqli_fetch_array($result)) {   $id = $row['keyword_name'];        } // end while loop    print "<p> $row has been permanently deleted.</p>";     $sql="delete addkeywordtable keyword_name = '$id'";   echo "<meta http-equiv='refresh' content='2; url=addkeyword.php'>";   ?> 

any great.below screenshot of sql table addkeywordtable

sql db

in deletekey.php may have error:

require 'db.php'; $sel_key = $_post[sel_key];  //sql statement select information $sql = "select * addkeywordtable keyid = $sel_key"; 

should second line read $sel_key = $_post['sel_key']; instead?

this cause record never selected in query follows.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -