Results 1 to 5 of 5

Thread: Deleting SQL Entries with a PHP form

  1. #1
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Deleting SQL Entries with a PHP form

    Im in need of a lil help here.

    atm ive been learning up with php and sql, tho im stuck with the connection between allowing to delete.

    i went on a google hunt and found this:

    PHP Code:
    <?PHP
    $dbuser
    ="gamer_simple";
    $dbpass="*******";
    $dbname="gamer_simplephp";  //the name of the database
    $chandle mysql_connect("localhost"$dbuser$dbpass
        or die(
    "Connection Failure to Database");
    mysql_select_db($dbname$chandle) or die ($dbname " Database not found. " $dbuser);

    $mainsection="forum_question"//The name of the table where web links are stored
    $idno=1;
    $query1="delete from " $mainsection " where id = " $idno;
    mysql_db_query($dbname$query1) or die("Failed Query of " $query1);
    echo 
    "Forum Question with ID " $idno " has been deleted as requested.<br>";
    ?>
    Im looking for something like that, tho with a form which shows all the ID,s and titles with a tick box next to them. so its easier to delete them without having to keep changing it an uploading via ftp then going to the script.

    ive posted here before and u didnt let me down. i hope this trip is the same
    Last edited by Snookerman; 04-22-2009 at 02:06 PM. Reason: added “Resolved” prefix

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Maybe this?
    Jeremy | jfein.net

  3. #3
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Here is the correct syntax for deleting:

    PHP Code:
    $q "DELETE FROM `table` WHERE `table`.`column` = 'value' LIMIT 1; 
    Place double quotes around the whole query string. Place single quotes around variables. Place `forward ticks` around database and column names. DO NOT quote integers.

    For your example, $mainsection is a column name, so place `forwardticks` around it. id is a column name so it gets forward ticks. $idno is a variable and would normally get 'single quotes', but since it is an integer, do not quote it. LIMIT 1 makes sure only one row is deleted.

    PHP Code:
    $q "DELETE FROM `$mainsection` WHERE `id` = $idno LIMIT 1 "
    Good Luck,

    J

  4. #4
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    jason, thanks for the help but i was looking for more of a form which did it.

    Nile got it just perfect

    thanks a bunch mate.

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Great! Glad to help you! Your welcome!

    It seems your topic is solved... Please set the status to resolved.. To do this:
    Go to your first post ->
    Edit your first post ->
    Click "Go Advanced" ->
    Then in the drop down next to the title, select "RESOLVED"
    Jeremy | jfein.net

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
  •