PHP - Button to delete Item from MySQL -


I'm coding some video upload script and I'm just from the admin panel. There is a list with all my videos there. And on the right side of each video there is a Delete button when I click on the button, then this video should be removed from the database, but after clicking on the button it should not work if nothing is done.

  & lt ;? Php $ query = mysql_query ("SELECT * FROM` videos` "); While ($ line = mysql_fetch_assoc ($ query)) {$ id = $ row ['id']; $ Name = $ line ['name']; Encoder "& lt; a href = 'watch.php? Id = $ id' & gt; $ name & lt; / a & gt; & lt; br / & gt; input type = 'submit' name = ' Remove 'value =' Delete '& lt; br / & gt; "; } If {ifet ($ _ POST ['remove'])) {foreach ($ _POST ['id'] $ the_id) {if (! Mysql_query ("Exit from video where id = '$ the_id'") ) {Echo mysql_error (); }}}? & Gt;   

Definitely I have a MySQL connect query on the header. This is the only php code to list and try to delete all the videos.

This is an example of doing this with MySQLi, with binding parameters to avoid SQL injection -

  if (isset ($ _ POST ['remove'])) {$ remove = $ mysqli-> gt; Video `where` id =? "); $ Vid_id = $ _POST ['vid_id']; $ delete- & gt; band_arm ('s', $ vid_id); if (! $ Delete- & gt; execute (=== true) {echo $ mysqli-> error;}} $ Query = "SELECT * FROM` video`"; if ($ result = $ mysqli-> query ($ query)) {while ($ row = $ result-> ; fetch_object ()) {$ id = $ row-> id = $ name- $ row-> name, echo "& lt; A href = 'watch.php? Id = $ id '& gt; $ Name & lt; / A & gt; & Lt; Br / & gt; "; echo" & lt; form name = 'delete_vid' method = 'post' & gt; "; echo" & lt; Input type = 'hidden' name = 'vid_id' value = '$ id' & gt; "echo" & lt; Input type = 'submit' name = 'remove' value = 'delete' & lt; Br / & gt; "; echo" & lt; / Form> ";}} and {echo mysqli_error ($ connection);} $ result- & gt; off ();   

Of course you must provide a $ connection from the database, But you must start with MySQLi only, but by adding a form for each video.



Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -