Forum Moderators: coopster

Message Too Old, No Replies

getting db fields

sorry to ask a simple Q, but...

         

Smad

11:16 pm on Nov 27, 2003 (gmt 0)

10+ Year Member



I have looked through posts and looked through my book but to no avail, I expect this is easy but for some reason i keep going wrong..

I have a page that displays DB records..on this php file is a delete this record link. the link passes a var.

I have 2 files in dir's which need deleting which are pathed from the record.

So basically i need to access the record and tell the db to delete it and then unlink the 2 files refered to within the db record...

TIA for any help.

jatar_k

11:21 pm on Nov 27, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would think you should select the paths first and then fire off the delete queries then use the data from the path column once the delete query has succeeded.

I would assume you have the id of the row to work with in this process.

select path from table where id=$id

keep the path value somewhere and then fir off the delete

delete from table where id=$id

then if that doesn't return an error do the
unlink($path);

Smad

8:08 am on Nov 28, 2003 (gmt 0)

10+ Year Member



this is my code, but i cant get it to put the path into $upfiledir and $thumb respectively

include_once('db.php');
$conn = db_connect();

$model = $HTTP_GET_VARS['model'];
$query = "select from cars where model = $model";
$result = mysql_query($query,$conn);

$upfiledir = $result['picture'];

$thumb = $result['thumb'];
unlink($upfiledir);
unlink($thumb);

liketoseeyoutry

8:41 am on Nov 28, 2003 (gmt 0)

10+ Year Member



I'm not sure if you can access the fields directly from the $result variable, but hey, I've never tried :P

Here's what I'd do in that case though ...

include_once('db.php');
$conn = db_connect();

$model = $_GET['model']; // Same as HTTP_GET_VARS
$query = "select from cars where model = $model";
$result = mysql_query($query,$conn);
$row = mysql_fetch_array($result);

$upfiledir = $row['picture'];

$thumb = $row['thumb'];
unlink($upfiledir);
unlink($thumb);

Smad

8:50 am on Nov 28, 2003 (gmt 0)

10+ Year Member



liketoseeyoutry

i tried and it wasnt happy :(

thanks guys for the help.

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Smad

12:10 pm on Nov 28, 2003 (gmt 0)

10+ Year Member



Does anyone else know what I may have done wrong please?

coopster

5:34 pm on Nov 28, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It seems as though your query may be wrong. Print out the query to see:

$model = $_GET['model']; // Same as HTTP_GET_VARS
$query = "select from cars where model = $model";
exit($query);
$result = mysql_query($query,$conn);

I'm guessing that it's a syntax error as you aren't selecting any fields for one thing, and I always surround strings and dates with quotations:


$query = "select * from cars where model = '$model'"; // <-- surround text strings with quotes!