Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Delete specific image from the database [simple php/mySql]
- <form method="post">
- <ul>
- <?php
- $host = "127.0.0.1"; //database location
- $user = ""; //database username
- $pass = ""; //database password
- $db_name = ""; //database name
- if(!$link = mysql_connect($host, $user, $pass)) {
- echo "<p>error: ".mysql_error()."</p>";
- } else {
- mysql_select_db($db_name);
- }
- $selectAll = "SELECT image_name FROM home_images";
- $doIt = mysql_query($selectAll);
- // if(isset($_POST['delete'])) {
- // mysql_query("DELETE FROM home_images WHERE image_name = ");
- // }
- ?>
- <?php while($result = mysql_fetch_array($doIt)) : ?>
- <li style="display:inline; margin-right:10px">
- <img src="<?php bloginfo('url') ?>/wp-content/uploads/<?php echo $result[0]; ?>" height=50 width=60 />
- <input type="hidden" value="<?php echo $result[0]; ?>" name="imagename" />
- <input type="submit" value="X" name="delete" />
- </li>
- <?php endwhile; ?>
- <?php
- if(isset($_POST['delete'])) {
- $imagename = $_POST['imagename'];
- $deleter = "DELETE FROM home_images WHERE image_name = '$imagename'";
- if(mysql_query($deleter)) {
- echo "Successful!";
- echo $imagename;
- } else {
- echo mysql_error();
- }
- }
- ?>
- </ul>
- </form>
- <?php while($result = mysql_fetch_array($doIt)) : ?>
- <li style="display:inline; margin-right:10px">
- <form method="post">
- <img src="<?php bloginfo('url') ?>/wp-content/uploads/<?php echo $result[0]; ?>" height=50 width=60 />
- <input type="hidden" value="<?php echo $result[0]; ?>" name="imagename" />
- <input type="submit" value="X" name="delete" />
- </form>
- </li>
- <?php endwhile; ?>
- <?php while($result = mysql_fetch_array($doIt)) : ?>
- <li style="display:inline; margin-right:10px">
- <img src="<?php bloginfo('url') ?>/wp-content/uploads/<?php echo $result[0]; ?>" height=50 width=60 />
- <div <!--some kind of formatting here i suppose-->>
- <input type="radio" value="<?php echo $result[0]; ?>" name="imagename" />
- </div>
- </li>
- <?php endwhile; ?>
- <?php
- if(isset($_POST['delete'])) {
- $imagename = $_POST['imagename'];
- $deleter = "DELETE FROM home_images WHERE image_name = '$imagename'";
- if(mysql_query($deleter)) {
- echo "Successful!";
- echo $imagename;
- } else {
- echo mysql_error();
- }
- }
- ?>
Add Comment
Please, Sign In to add comment