SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Delete record from database

    Hi,

    I have created a database, where it is possible to create posts and see them on a different page.

    On the page where it's possible to see all the records I want to create a delete link so it is possible to delete the record where you have pressed the delete link.

    I have written some code, but it doesn't delete the record it only refreshes the page witch is called se_kunder.php

    Can you please help me with what's missing? aren't I executing the delete sql query, or how do I do that?

    I hope you understand what I meen.
    Thank you for your help.
    Here is the code:

    Code PHP:
     
    <?php
    $con = mysql_connect("xxx","xxx","xxx");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
     
    mysql_select_db("xxx", $con);
     
    $id = $row['ID'];
    $result = mysql_query($sql);
     
     
     
     
    $result = mysql_query("SELECT * FROM kunder");
     
     
     
     
    $sql = "DELETE FROM kunder WHERE ID='$id'"; 
     
     
     
    while($row = mysql_fetch_array($result))
     
     
     
      echo "<b>NY KUNDE</b>" . "<br><br><b /><u>Virksomhedsnavn</u></b><br>" . $row['Virksomhedsnavn'] . "<br><br><b><u>CVR. nummer</u></b> <br> " . $row['cvrnummer']  . 
      "<br><br><b /><u>Kontaktperson</u></b><br>" . $row['kontaktperson'] . "<br><br><b><u>E-mail</u></b> <br> " . $row['email'] . 
      "<br><br><b /><u>kundenummer</u></b><br>" . $row['kundenummer'] . "<br><br><b><u>fakturanummer</u></b> <br> " . $row['fakturanummer'] .
      "<br><br><b /><u>oprettet</u></b><br>" . $row['oprettet'] . "<br><br><b><u>brugernavn til ftp</u></b> <br> " . $row['brugerftp'] .
      "<br><br><b /><u>kodeord til ftp</u></b><br>" . $row['passftp'] . "<br><br><b><u>brugernavn til cms</u></b> <br> " . $row['brugercms'] .
      "<br><br><b /><u>kodeord til cms</u></b><br>" . $row['passcms'] . "<br><br><b><u>udbyder</u></b> <br> " . $row['hosters'] .
      "<br><br><b /><u>betalt</u></b><br>" . $row['betalt'] . "<br><br><b><u>skal betale senest</u></b> <br> " . $row['betalsenest'] .
      "<br><br><b /><u>send neste faktura</u></b><br>" . $row['nestefaktura'] . "<br><br><b><u>pris</u></b> <br> " . $row['pris'] . 
      "<br><br><b /><u>webadresse</u></b><br>" . $row['webadresse'] . "<br><br><b><u>link til faktura</u></b> <br> " . $row['fakturaurl'] .    
      "<br><br><b /><u>link til projektbeskrivelse</u></b><br>" . $row['projektbeskrivelseurl'] . "<br><br><b><u>noter</u></b> <br> " . $row['noter']. "<br><br>" .
      '<a href="se_kunder.php?id=$id\">Slet</a>' .
      "<br><br>" .
      "<hr />";;
     
     
     
    mysql_close($con);
    ?>

  2. #2
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this and see if it works for you-

    $sql="delete from mytable where ID= ".$id;

  3. #3
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No it still just refreshed the page

  4. #4
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $id = $row['ID'];

    Since the above is outside the while loop .The query doesn't get the id number.
    Try putting id=some number you have in database and see if that works. If that works then

    Put

    $id = $row['ID'];

    $sql = "DELETE FROM kunder WHERE ID='$id'";

    inside while loop. Good Luck.

  5. #5
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It still didn't work with the id number
    and if I put something under the while loop, it didn't show the post at all but the post is still in the databse.

    Did I maybe make the while loop wrong?

    thx

  6. #6
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know now what you are looking for.See if the following link helps you.
    What you need do to is create a delete button and pass the id in url to the delete php page.Don't try to add select and delete on the same page.

    http://blog.chapagain.com.np/very-si...isplay-in-php/


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
  •