SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi everyone, I am trying to set up a content management system and am having difficulties. I am using the following php template furnished by Kevin Yank.....But it is not deleting any records......

    <HTML>
    <HEAD>
    <TITLE> Delete Business Listing </TITLE>
    </HEAD>
    <BODY>
    <?php


    $cnx = mysql_connect('localhost','XXXXX','ZZZZZZ');
    mysql_select_db('ZZZZ');


    // Delete all jokes belonging to the author
    // along with the entry for the author.
    $ok1 = mysql_query("DELETE FROM Business WHERE ID=$businessid");
    if (!$ok1) {
    echo("<P>Business listing deleted successfully!</P>");
    } else {
    echo("<P>Error deleting business listing from database!<BR>".
    "Error: " . mysql_error());
    }


    ?>

    </BODY>
    </HTML>

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have a form on another page or something? You need to get the "$businessid" variable to it somehow to let it know which record you want to delete.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, the businessid is coming from another form......When I hit delete, it says I successfuly deleted the record. But nothing is really deleted...

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the problem is that you have your if/else commands backwords.

    Right now you have it like this:


    $ok1 = mysql_query("DELETE FROM Business WHERE ID=$businessid");
    if (!$ok1) {
    echo("<P>Business listing deleted successfully!</P>");
    } else {
    echo("<P>Error deleting business listing from database!<BR>".
    "Error: " . mysql_error());
    }


    The "!" in front of $ok1 means the opposite - IE: if $ok1 is not valid. Because of this, the "deleted successfully" messages should be in the ELSE statement, and the error echo commadn in the if, like this:


    $ok1 = mysql_query("DELETE FROM Business WHERE ID=$businessid");
    if (!$ok1) {
    echo("<P>Error deleting business listing from database!<BR>".
    } else {
    echo("<P>Business listing deleted successfully!</P>");
    "Error: " . mysql_error());
    }


    I could be wrong, but I think that's it. You'd then of course be given an error message to give you more input into things. Also: are you sure the ID field is named "ID" in the SQL table? Are you sure the field sending the ID number is called "businessid"? Little typos in such places can really throw a person off sometimes.

  5. #5
    SitePoint Member
    Join Date
    Jan 2000
    Location
    North Bend, Oregon USA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $ok1 = mysql_query("DELETE FROM Business WHERE ID=$businessid");
    If the ID is a string, might try single quoting $businessid.
    Code:
    $ok1 = mysql_query("DELETE FROM Business WHERE ID='$businessid'");
    .

    Dan

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for everyone's help...But I found a great shareware program for mysql administration....It is so easy to use...Check it out!

    http://popeye.snu.ac.kr/~smkim/mysql


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •