Jump to content

PHP Directory Delete and MySql Row delete Help Please


Ult1matek1ll

Recommended Posts

I'm trying to set it so that it will delete an entire populated directory based upon a value in the database then after finishing that to go back and delete that row in the database.  my current code is

 

<?php $page_title = "Central Valley LLC | Photo Addition" ?>
<?php include("header.php"); ?>
<?php include("nav.html"); ?>
		<div id="content">
			<form action="delprod.php" method="post" enctype="multipart/form-data">
				<label for="which">Choose A Product To Remove:</label>
				<?php $con = mysql_connect("localhost","phoenixi_cv","centraladmin");
					if (!$con)
					{
						die('Could not connect: ' . mysql_error());
					}
					mysql_select_db("phoenixi_cvproducts", $con);
					$result = mysql_query("SELECT * FROM Products");
					echo "<select name=\"which\">";
					while($row = mysql_fetch_array($result))
  						{
						echo "<option ";
						echo "value=\"" . $row['id'] . "\">";
						echo $row['Name'] . "</option>";
					}
					echo "</select>";
					mysql_close($con);
				?>
				<br />
				<input type="submit" name="submit" value="Submit" />
			</form>		
		</div><!--#content-->
<?php include("footer.html") ?>

 

 

and the delete script

 

<?php
$con = mysql_connect("localhost","phoenixi_cv","centraladmin");
					if (!$con)
					{
						die('Could not connect: ' . mysql_error());
					}
					mysql_select_db("phoenixi_cvproducts", $con);
					$result = mysql_query("SELECT id FROM Products WHERE id=$_POST['which']");
					$row = mysql_fetch_array($result)


					chdir('assets');
					chdir('images');
					$mydir = $row . '/';
					$d = dir($mydir);
					while($entry = $d->read())
					{
						if($entry!="." && $entry!="..")
						{
							unlink($_POST['which'] . '/' . $entry);
						}
					}
					rmdir($mydir);
					$result = mysql_query("DELETE * FROM Producs WHERE id=$_POST['which']");
?>

 

Thank you in advance for all your help.  any easier ways of approaching this will be welcome as well

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.