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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.