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 7 of 7

Thread: deleting a row

  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile deleting a row

    I was wondering how to have an link near the mysql row that allows you to delete it?
    This is my code

    PHP Code:
    <?php include 'header.php';  // Works.


    ?>
    <div id="content">
       <div id="columnsC">

          <img  style="border:0;" src="siteimg/stixy.jpg" alt="stixy"/><Br/>
    <p>Stixy helps users organize their world on flexible, shareable Web-based bulletin boards called Stixyboards. Unlike most personal productivity or project management software, Stixy doesn't dictate how users should organize their information. Users can create tasks, appointments, files, photos, notes, and bookmarks on their Stixyboards, organized in whatever way makes sense to them. Then they can share Stixyboards with friends, family, and colleagues.</p>
       </div>
    <div id="columnsD">
    <?
    /**
     * User has already logged in, so display relavent links
     */
    echo '
    '
    ;
    if(
    $session->logged_in){
    $dbh=mysql_connect ("localhost""my_user""my_pass") or die ('I cannot connect to the database because: ' mysql_error());
    mysql_select_db ("my_db");
    if(isset(
    $_GET['remove']) && $_GET['remove'] == '1'){
        
    $sql "DELETE FROM emailists WHERE stixy=('" $session->userinfo['email'] . "')";
            if(
    $sqlres mysql_query($sql)){
                echo 
    '<div id="mes"><ul><li>email address removed</li></ul></div>';
            }else{
                echo 
    mysql_error();
            }
    }
    //break
    if(isset($_GET['insert']) && $_GET['insert'] == 1) {
      
    $sql "SELECT stixy FROM emailists WHERE stixy = '{$session->userinfo['email']}'";
      if (
    $result mysql_query($sql)) {
        if (!
    mysql_num_rows($result)) {
          
    $sql "INSERT INTO emailists (stixy) VALUES ('" $session->userinfo['email'] . "')";
          if (
    $sqlres mysql_query($sql)){
            echo 
    '<div id="mes"><ul><li>email address added</li></ul></div>';
          } else {
            echo 
    mysql_error();
          }
        } else {
          echo 
    "<div id='mes'><ul><li>email address already exists</li></ul></div>";
        }
      } else {
        echo 
    mysql_error();
      }
    }
    $query mysql_query("SELECT stixy FROM emailists WHERE stixy = '{$session->userinfo['email']}'");

    $result mysql_num_rows($query);

    if(
    $result !== 0){

    echo 
    "<ul><li><a href='stixy.php?remove=1'>Remove yourself from the list[/url]</li></ul>";

    } else {

    echo 
    "<ul><li><a href='stixy.php?insert=1'>Add yourself to the list[/url]</li></ul>";

    }

    echo 
    "<ul>";
      
    $sql "SELECT stixy FROM emailists";
      if (
    $result mysql_query($sql)) {
        if (
    mysql_num_rows($result)) {
          while (
    $row mysql_fetch_assoc($result)) {
            echo 
    "<li>";  echo $row['stixy'] . "</li>";
           
          }
        }
      }
    echo 
    "</ul>";

     }
    else{
    ?>


    <p style="border-style: solid;
    border-width: 3px;">some text here</p>

    <?
    }
    ?>

    </div>



       <?php include 'sidebar.php'?>
       <div style="clear: both;">&nbsp;</div>
    </div>
    <?php include 'footer.php';  // Works.

    ?>

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    what are you trying to delete exactly? And what does your code do?
    There are some variables that I am unclear of.

    P.S how does this session class work? Are you writing all of your session to a class or something. I'm only asking in case the problem is that the session arn't being maintained with session_start()?
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would like a link next to each row that deletes that row from the mysql database

  • #4
    New Coder
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Help!
    Last edited by nathanmaxsonadi; 08-01-2007 at 08:13 PM. Reason: I actully did not find out how to do it :(

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    I presume what you mean is you have a list of items (extracted from DB data) on your page and you would like a delete button next to each item. So you can delete that item?
    if so you can have a button next to it that send its ID through the GET request.

    Code:
         item 1<a href="delete.php?remove=1&ID=".$ID >Delete</a>';
    just make sure you validate the users session date before you delete dont rely on the GET request data alone or you'll be asking from trouble
    You can not say you know how to do something, until you can teach it to someone else.

  • #6
    New Coder
    Join Date
    Jul 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What would delete.php be then?

  • #7
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    the page with the code that processes the form data and deletes that row item. So replace that for the name of the scripts file
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

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