#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    2
    Rep Power
    0
    Hi All.

    First time poster at this forum!

    Great to see the support here.

    Well, my question is a newbie question, that I'm sure is pretty easy, but I just can't figure it out!

    I've got a simple PHP & MySQL database script that I'm working with. I have figured out how to 'add' and 'view' the data in the database, but I can't figure out how to delete the data.

    To get to the code here...

    Here are my variables: (not real, just for example sake)


    $hostname = "YourHostName";
    $username = "YourUsername";
    $password = "YourPassword";
    $userstable = "LinksTable";
    $dbName = "YourDatabaseName";

    Here are my tables fields:

    ID
    LinkName
    LinkURL
    LinkDescription
    email
    UserName
    UserPassword (which I don't use yet!)


    Ok, with that stuff out of the way...

    I am in need of the syntax code to be able to place within my admin.php3 file to be able to delete a line from within the database table.


    Ok, now here is my complete admin.php3 code:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <html>
    <head>
    <title> Links Database - Admin Page </title>
    </head>
    <body text=black link=red vlink=red alink=yellow>

    <?

    /* declare variables */
    $hostname = "YourHostName";
    $username = "YourUsername";
    $password = "YourPassword";
    $userstable = "LinksTable";
    $dbName = "YourDatabaseName";
    $VLDir = "http://www.PathToYour/Diretory";
    // set this to the directory where your main files are!
    // DO NOT include a closing "/" on the $VLDir variable!

    /* make connection to database */
    MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");

    @mysql_select_db( "$dbName") or die( "Unable to select database");

    /* Select all from within database */
    $query = "SELECT * FROM $userstable";

    $result = MYSQL_QUERY($query);

    /* How many users are there? */
    $number = MYSQL_NUMROWS($result);

    /* Print these results to the screen */
    $i = 0;

    IF ($number == 0) :
    PRINT "<P><font face=Verdana Size=1><a href="$VLDir/insert.php3"><B>Add A Link</B></a>";
    PRINT "<p><br>";
    PRINT "<I><B>There Are Presently No Links!</B></I>";
    ELSEIF ($number > 0) :
    PRINT "<P><font face=Verdana Size=1>Total Number of Links: $number | <a href="$VLDir/insert.php3"><B>Add Your Link</B></a>";
    PRINT " <hr color=black width=60% align=left><BR>";
    WHILE ($i < $number):
    $LinkName = mysql_result($result,$i,"LinkName");
    $LinkURL = mysql_result($result,$i,"LinkURL");
    $LinkDescription = mysql_result($result,$i,"LinkDescription");
    $email = mysql_result($result,$i,"email");
    $UserName = mysql_result($result,$i,"UserName");
    $UserPassword = mysql_result($result,$i,"UserPassword");
    PRINT "<font face=Verdana Size=1><B>Site Name:</B> $LinkName<BR>";
    PRINT "<font face=Verdana Size=1><B>Site URL:</B> <a href="$LinkURL" target="_blank">$LinkURL</a><BR>";
    PRINT "<font face=Verdana Size=1>S<B>ite Description:</B> $LinkDescription<BR>";
    PRINT "<font face=Verdana Size=1><B>* User Name:</B> $UserName<BR>";
    PRINT "<font face=Verdana Size=1><B>* User Password:</B> $UserPassword<BR>";
    PRINT "<font face=Verdana Size=1><B>* Email address:</B> <a href="mailto:$email">$email</a><BR>";
    PRINT "<BR><BR>";
    $i++;
    ENDWHILE;
    PRINT "</CENTER>";
    ENDIF;
    ?>
    <p><br>
    <hr width=40% align=left color=black>
    Copyright 4CM, 1996-2000 - <a href="http://www.4cm.com" target="_blank">www.4cm.com</a><br>
    Links Database Powered By: <a href="http://www.4cm.com" target="_blank">www.4cm.com</a>
    </body>
    </html>
    [/code]

    Can anyone here help me with the next step of this admin page... I need a way to be able to "DELETE" a given entire.

    I would be really grateful!

    (sure hope all this makes sense!)

    Later All.

    ------------------
    --- -- -- --- -- -- ---
    John B. Abela
    Owner, 4CM
    http://www.4cm.com/
    support@4cm.com
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    i am writing a simple delete script.

    just try in this way...

    $deleteresult = mysql_query ("DELETE FROM tablename WHERE id = '$id'");

    if (mysql_affected_rows($deleteresult) >= 1)
    { print "Successfully deletedn";
    }
    else
    {
    print "not deleted any rows";
    exit;
    }

    ------------------
    SR -
    shiju.dreamcenter.net
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    2
    Rep Power
    0
    Thanks for the bit of code!

    However, I'm still unsure what to do.

    Should I place the code you wrote in a seperate file? (for instance: delete.php3)??

    Or should I include it within the existing "admin.php3" file that I have?

    And, either way, what would the html code be to call it?

    Sorry for the real basic questions...

    Later.

    ------------------
    --- -- -- --- -- -- ---
    John B. Abela
    Owner, 4CM
    http://www.4cm.com/
    support@4cm.com
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Yokhannan,

    you can include that delete script inside the "admin.php3" or you can create a separate delete.php3.either way it should work fine.

    include the following html tag in your admin.php3(or where ever you want to place it).

    <b>Delete a link:</b>
    <form action="delete.php3" method="post">
    Link name<input type="text" name="link_name">
    <input type="submit" name="delete" value="Remove Now">
    </form>

    In delete.php3:


    if($delete=="Remove Now"){
    $deleteresult = mysql_query ("DELETE FROM tablename WHERE linkname = '$link_name'");

    if (mysql_affected_rows($deleteresult) >= 1)
    { print "Link has been removed successfullyn";
    }
    else
    {
    print "Error !! couldn't remove the link";
    exit;
    }
    }


    if you are using this delete script in admin.php3 then use the form html tag

    <form action="admin.php3" method="post">
    ---
    --

    and use delete script inside the admin.php3.


    (you can modify the above script according to your requirment)

    Hope this may help you to finish your assainment successfully.

    GOOD LUCK!!!!!





    ------------------
    SR -
    shiju.dreamcenter.net

Similar Threads

  1. Can't move or delete it!
    By Hykinsel007 in forum Windows Help
    Replies: 3
    Last Post: June 15th, 2004, 04:41 PM
  2. Replies: 2
    Last Post: September 22nd, 2003, 10:27 PM
  3. delete onEnterFrame
    By wyclef in forum Flash Help
    Replies: 6
    Last Post: June 11th, 2003, 05:23 PM
  4. SELECT records between two months
    By C3P0 in forum MySQL Help
    Replies: 6
    Last Post: April 4th, 2003, 05:56 PM
  5. delete folder tree...
    By joyce in forum PHP Development
    Replies: 15
    Last Post: December 3rd, 2001, 09:54 PM

IMN logo majestic logo threadwatch logo seochat tools logo