No I’m fetching specifically the file name.
So $dierctory = “uploadsfolder/” . $filename
$filename = “hello.jpeg”
I query the database for the filename hello.jpeg then connect it into the uploads/ folder to combine into
a path to unlink() it
No I’m fetching specifically the file name.
So $dierctory = “uploadsfolder/” . $filename
$filename = “hello.jpeg”
I query the database for the filename hello.jpeg then connect it into the uploads/ folder to combine into
a path to unlink() it
ok lets see if this mysql guy can figure out a pdo
what exactly is it doing when you call that code
It will remove only the first photo in the database. so its just telling the query to delete the first row. now the row with tyhe directory selected. why is this?
have you tried like the mysql while loop to fetch all the instances of the table columns including the directory
or [php while($row = $stmt->fetch()){ …[/php]
type stuff because you need to get all the ones that have that directory right
or [php] while($row = $stmt->fetch()){ …[/php]
type stuff because you need to get all the ones that have that directory right
sorry bout that
If you mean, the while() statement, like while $result = $sql -> fetch(), then yes. I fetched
all row data into the $result variable. I retreived it like $result [“Directory”]. When i queried with it,
it didnt give the directory of each photo like intended for, but it instead deletes the first row in the database.
How do I get the directory of each image into a variable, so i can use it for deleting and unlink()?
but it looks like you didnt fetch it when you are asking it to delete all those that use the same directories
msql = $conn->prepare("DELETE FROM uploads WHERE Directory = ?");
Oh i see. so can you give me an example of the corrected code?
[php]
if (isset($_POST[“delete”]))
{
$file = $result [“Directory”];
unlink(“uploads/” . $file);
$msql = $conn->prepare(“DELETE FROM uploads WHERE Directory = ?”);
while ($result = $sql -> fetch())
{
$msql->execute(array($file));
$msql->execute();
}
}
[/php]
doin best i can w/pdo but along that lines
Your code worked until it wont delete the first result. But wait i found an alternative…
What if i was supposed to submit the delete button to a file called delete.php with the delete and unlink()
script on it. and instead of messing arround with fetching and exporting the $result [“Directory”],
we simple transported the path with the $_GET method in the address bar? then in the delete/unlink script (delete.php) we can just $_GET it from the address bar. correct? then once it deletes everything, it header()
redirects to the profile/gallery page. correct?
are you only deleting one or many form the same directory
because a while loop should find all that have the where clause
everything is in the uploads folder. but do you like the alternative?
Wait whaT?
ok so you have your session id for the user and if he wants to delete that picture if it is his he can and when he does he can only delete that picture from that button right
does the picture have a unigue id for it
you can call that in your where clause when it looks for what to delete
Correct. The if statements make sure the userid is his and that he is logged on before displaying the button.
The button leads hime to the script page, which $_GET the filename (the directory) from the address bar
and delete and unlink from there. so it all comes from the address bar instead of doing what we were doing before. simpler i think, right?
yes you can do that but i mean unique id as in not the session userid but the id of the picture and you can use that in your where clause if your code doesnt work
The pics dont have id’s though.