0

I'm trying to delete records from my database using a form. Can't get this to work. Any ideas?

include 'newsconnect.php';
$Id = $_POST['Id'];
if (empty($Id) === true {
    echo 'please input an Post ID.';
} else {
    if(!$_POST['Submit']) {
        header('Location: http://www.hidensecrets.yourwebsolution.net/forum.php');
    } else {
        mysql_query("DELETE * FROM forum WHERE id = '$Id'") or die(mysql_error());
        header('Location: http://www.hidensecrets.yourwebsolution.net/forum.php') ;
        echo "Deleted!";        
    }
}

I seem to land on this page which displays no errors.
Any help is really appreciated.

zajonc
  • 1,935
  • 5
  • 20
  • 25

3 Answers3

3

Missing a closing bracket:

include 'newsconnect.php';
$Id = $_POST['Id'];
if (empty($Id)) {
           //-^    
    echo 'please input an Post ID.';
} else {
    if (!$_POST['Submit']) {
        header('Location: http://www.hidensecrets.yourwebsolution.net/forum.php');
    } else {
        mysql_query("DELETE FROM forum WHERE id = '$Id'") or die(mysql_error());
        header('Location: http://www.hidensecrets.yourwebsolution.net/forum.php');
        echo "Deleted!";
    }
}

Not sure which IDE you're using but most of them would show this error. You're also open to sql injection. Find out more.

Community
  • 1
  • 1
SeanWM
  • 16,789
  • 7
  • 51
  • 83
0

What sort of issue are you facing? You're missing a closing parenthesis for if (empty($Id) === true in case the you're getting syntax error

Ejaz
  • 8,719
  • 3
  • 34
  • 49
0

I think that you must omit the asterisk in your delete query ! Try it and tell me the result :)

your code must use this query :

mysql_query("DELETE FROM forum WHERE id = '$Id'") or die(mysql_error());

instead of this one :

mysql_query("DELETE * FROM forum WHERE id = '$Id'") or die(mysql_error());

Hope this it will be the solution :)

Last Breath
  • 530
  • 2
  • 12
  • @Matt Brady your code must use this query : mysql_query("DELETE FROM forum WHERE id = '$Id'") or die(mysql_error()); instead of this one : mysql_query("DELETE * FROM forum WHERE id = '$Id'") or die(mysql_error()); Hope this it will be the solution :) – Last Breath Mar 29 '13 at 00:43