Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Having problems with mysql deteting from database using php form

    Hi Guys
    I am having problems with my database deleting data from my php form and here is my code I have:

    Alright I was able to get the script to add names but having issues on deleting from database

    DELETE FROM `vmail`.`alias` WHERE `alias`.`address` = 'test7@domain.com';

    this is the code from delete.php
    Code:
    <?php
    $id = $_GET['address'];?>
    <div align="center">
    <h2>Are you sure?</h2>
    <h2><a href="deleted.php?address=<?php echo "$id" ?>">Yes</a> - <a href="index.php">No</a></h2>
    </div>
    then this is deleted.php code
    Code:
    <a href="index.php">Back to List</a><br>
    <br>
    <?php 
    include("connect.php");
     
    $id = $_GET['address'];
     
    $delete = "DELETE FROM alias WHERE id = '$id' ";
    mysql_query($delete);
    mysql_close();
     
    echo "Entry deleted";
     
    ?>
    but the database of vmail is already selected but its getting table information from alias.

  • #2
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    View your source and make sure that the correct id is being sent. And on a side note, you should NEVER send raw user submitted data to a database. See http://php.net/manual/en/function.my...ape-string.php.
    "Yeah science!"
    Online Science Tools

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,939
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Bring the page up in your browser.

    Click on the browser's VIEW menu.

    Click on the SOURCE or PAGE SOURCE menu item.

    Find the HTML code that corresponds to that PHP code.

    Look at what the <a href=> shows you .

    HINT: It's going to show something like
    Code:
    <a href="deleted.php?address="173">Yes</a>
    So now, when you do $_GET["address"], the value you get is "173".
    Yes, with the quote marks.

    KABLOOEY.

    In short, kill the quote marks.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I looked and it doesnt show anything what your saying in there. I guess if I have to delete the email address I will do it from inside of phpmyadmin since the coding isnt working bc I used the coding from this website: http://www.turningturnip.co.uk/free-...php-generator/ then I just took it out the id since my database wasnt using id format.


    Quote Originally Posted by Old Pedant View Post
    Bring the page up in your browser.

    Click on the browser's VIEW menu.

    Click on the SOURCE or PAGE SOURCE menu item.

    Find the HTML code that corresponds to that PHP code.

    Look at what the <a href=> shows you .

    HINT: It's going to show something like
    Code:
    <a href="deleted.php?address="173">Yes</a>
    So now, when you do $_GET["address"], the value you get is "173".
    Yes, with the quote marks.

    KABLOOEY.

    In short, kill the quote marks.
    Last edited by treichhart; 01-22-2012 at 04:10 PM.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,939
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Quote Originally Posted by treichhart View Post
    I looked and it doesnt show anything what your saying in there.
    Okay, so show us what the HTML *does* look like.

    Don't make us guess.

    And yes, you can do it via phpmyadmin, but man is that a clumsy way to run a website!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Alright here is the original code from: http://www.turningturnip.co.uk/free-...php-generator/

    delete.php code:

    Code:
    <?php
    /// In order to use this script freely
    /// you must leave the following copyright
    /// information in this file:
    /// Copyright 2006 www.turningturnip.co.uk
    /// All rights reserved.
    
    $id = $_GET['id'];?>
    <div align="center">
    <h2>Are you sure?</h2>
    <h2><a href="deleted.php?id=<?php echo "$id" ?>">Yes</a> - <a href="index.php">No</a></h2>
    </div>
    and here is mine delete.php code

    Code:
    <?php
    $address = $_GET['address'];?>
    <div align="center">
    <h2>Are you sure?</h2>
    <h2><a href="deleted.php?address=<?php echo "$address" ?>">Yes</a> - <a href="index.php">No</a></h2>
    </div>
    here is the code deleted.php from http://www.turningturnip.co.uk/free-mysql-php-generator :
    Code:
    <a href="index.php">Back to List</a><br>
    <br>
    <?php 
    /// In order to use this script freely
    /// you must leave the following copyright
    /// information in this file:
    /// Copyright 2006 www.turningturnip.co.uk
    /// All rights reserved.
    
    include("connect.php");
    
    $id = $_GET['id'];
    
    $delete = "DELETE FROM alias WHERE id = '$id' ";
    mysql_query($delete);
    mysql_close();
    
    echo "Entry deleted";
    
    ?>
    and here is mine deleted.php code
    Code:
    <a href="index.php">Back to List</a><br>
    <br>
    <?php 
    include("connect.php");
    
    $id = $_GET['address'];
    
    $delete = "DELETE FROM alias WHERE address = '$address' ";
    mysql_query($delete);
    mysql_close();
    
    echo "Entry deleted";
    
    ?>

    but my database does not have id in it at all. It only have vmail,alias,address,goto domain.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,939
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    As I read your code, what the HTML is currently looking like is probably
    Code:
    <a href="deleted.php?address="test7@domain.com">Yes</a>
    And that means your SQL query will end up looking like
    Code:
        DELETE FROM alias WHERE id = '"test7@domain.com"'
    So I say again, kill the quote marks.

    You could easily find out if I'm correct with just the TINIEST bit of DEBUGGING.

    Code:
    <a href="index.php">Back to List</a><br>
    <br>
    <?php 
    include("connect.php");
     
    $address = $_GET['address'];
     
    $delete = "DELETE FROM alias WHERE id = '$id' ";
    echo "<hr/>DEBUG SQL: " . $delete . "<hr/>\n";
    mysql_query($delete) or die(mysql_error);
    mysql_close();
     
    echo "Entry deleted";
    ?>
    Last edited by Old Pedant; 01-23-2012 at 12:01 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    treichhart (01-23-2012)

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,939
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    You did *NOT* show use the code I asked for.

    I want you to bring the PHP page with the <a> link for deleting up in your browser.

    The click on the VIEW menu of the browser.

    Then click on the SOURCE or PAGE SOURCE option of that menu.

    Then show us what HTML the browser is seeing. I do *NOT* want to see the PHP code again.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,939
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    IN any case, your deleted.php code is completely wrong.

    Code:
    <a href="index.php">Back to List</a><br>
    <br>
    <?php 
    include("connect.php");
    
    $address = $_GET['address']; // *NOT* $id!  You aren't using $id, so why get it???
    
    $delete = "DELETE FROM alias WHERE address = '$address' ";
    mysql_query($delete);
    mysql_close();
    
    echo "Entry deleted";
    
    ?>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    here you go from the html coding



    so what do I need to do kill the " " or what do I need to do to fix this problem?

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,939
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Next time, just copy/paste the HTML code. That image makes it nearly impossible to read the text.

    Anyway, clearly you have a bug.

    Look at what is showing there:
    Code:
    <a href="deleted.php?id=">Yes</a>
    That does not match *AT ALL* the PHP code you showed us, which is this:
    Code:
    <?php
    $address = $_GET['address'];?>
    <div align="center">
    <h2>Are you sure?</h2>
    <h2><a href="deleted.php?address=<?php echo "$address" ?>">Yes</a> - <a href="index.php">No</a></h2>
    </div>
    Why does the HTML say id= when you claim the PHP code has address=?

    I think that you are still running the original code rather that your modified version. So it's never going to work until you get the right version of the code running.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    treichhart (01-23-2012)

  • #12
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    its probably in my index.php in this part of the code:

    echo "<a href=\"update.php?id=$id\">Update</a> <a href=\"delete.php?id=$id\">Delete</a>";

  • #13
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    There I corrected it and that worked and thanks for your help.

    I switched it to: echo "<a href=\"update.php?id=$id\">Update</a> <a href=\"delete.php?address=$address\">Delete</a>";


  •  

    Posting Permissions

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