deleting files from a MySQL dB

He has: 1,380 posts

Joined: Feb 2002

Hey, I want to delete files from a dB before submitting new ones...it doesn't work! I checked PHP.net, and it seems to be in correct form...

<?php
...connection and selection....
$result = mysql_fetch_array($query) or die(mysql_error());

if (
$result >= 1){
   
mysql_query(\"DELETE * FROM news WHERE $_POST[date] AND $_POST[text]\");
    };

...posting...
?>

it posts the new stuff fine, but doesn't delete the old ones. i tried ['date'] and such, but i get an error about T-STRING. i also tried
<?php
$result
= mysql_fetch_array($query) or die(mysql_error());

if (
$result >= 1){
   
mysql_query(\"DELETE * FROM news WHERE date=$_POST[date] AND text=$_POST[text]\");
    };
?>
with the same results and trials. What's wrong with this? Thanks!

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

<?php
// I'm assuming you actually need a number, no?
// And so your query is ...mysql_query(\"SELECT
// COUNT(*) FROM ... right?

// if you're using COUNT(*) then you won't have an array?
$result = mysql_fetch_array($query) or die(mysql_error());

// You should have a while loop here if you are getting an array
// If you are just counting, this should work

if ($result >= 1) {
   
$doit = mysql_query(\"DELETE *
        FROM news
        WHERE date='
$_POST[date]'
        AND text='
$_POST[text]'\");
    if (!
$doit) {
        echo mysql_error();
    }
}
?>

When in doubt, echo the $result and see what you're getting.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

http://ca3.php.net/manual/en/ref.mysql.php this may help with other mysql_* functions.

Also: http://ca3.php.net/manual/en/function.count.php if you count after getting the results, if you want to count the number of items that are returned in the array.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.