Deleting A Row in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flexsingh
    New Member
    • Mar 2008
    • 17

    Deleting A Row in PHP

    Hello there,

    I have been trying to delete a row in php for a long time now and its getting frustrating, can any see if they could possible help me please.

    My first page is

    Code:
    <?php
    // this starts the session 
    session_start(); 
    ?>
    <html>
    
    <head>
    <h1><font face="sans-serif, Arial" font color="white">Members Page!</h1>
    </head>
    
    <body background="main background1.jpg" link="yellow" vlink="yellow" hover="green" >
    <a href="blank.php">Back To Main page</a>
    
    <table align="center" width="600" border="0" cellspacing="0" cellpadding="1" >
    <tr>
    <td><font face="sans-serif, Arial" color="white" size= "-1">DESC Order</td>
    <td><a href="member_select_md.php"><font face="sans-serif, Arial" font font size= "-1">Member DESC</a></td>
    <td><a href="member_select_sd.php"><font face="sans-serif, Arial" font font size= "-1">Surname DESC</a></td>
    <td><a href="member_select_fd.php"><font face="sans-serif, Arial" font font size= "-1">Forename DESC</a></td>
    <td><a href="member_select_ad.php"><font face="sans-serif, Arial" font font size= "-1">Address DESC</a></td>
    <td><a href="member_select_dd.php"><font face="sans-serif, Arial" font font size= "-1">DOB DESC</a></td>
    </tr>
    <tr>
    <td><font face="sans-serif, Arial" color="white" font font size= "-1">ASC Order</td>
    <td><a href="member_select.php"><font face="sans-serif, Arial" font size= "-1">Member ASC</a></td>
    <td><a href="member_select_sa.php"><font face="sans-serif, Arial" font size= "-1">Surname ASC</a></td>
    <td><a href="member_select_fa.php"><font face="sans-serif, Arial" font size= "-1">Forename ASC</a></td>
    <td><a href="member_select_aa.php"><font face="sans-serif, Arial" font size= "-1">Address ASC</a></td>
    <td><a href="member_select_da.php"><font face="sans-serif, Arial" font size= "-1">DOB ASC</a></td>
    </tr>
    </table>
    <br><br><br>
    <table align="right" width="700" border="1" cellspacing="0" cellpadding="3" >
    <tr>
    
    <td align="center" width="12%"><b><u><font face="sans-serif, Arial" font color="white">Member No</b></u></td>
    <td align="center" width="13%"><b><u><font face="sans-serif, Arial" font color="white">Surname</b></u></td>
    <td align="center" width="13%"><b><u><font face="sans-serif, Arial" font color="white">Forename</b></u></td>
    <td align="center" width="40%"><b><u><font face="sans-serif, Arial" font color="white">Address</b></u></td>
    <td align="center" width="25%"><b><u><font face="sans-serif, Arial" font color="white">DOB</b></u></td>
    <td align="center" width="5%"></td>
    </tr>
    </table>
    <br><br><br><br>
    <?php
    $db_name="project"; // Database name
    $tbl_name="member"; // Table name
    
    // Connect to server and select database.
    mysql_connect($_SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $memberno=urlencode($_GET['Member_No']);
    
    // Retrieve data from database
    $sql="SELECT * FROM $tbl_name ORDER BY `Member_No` ASC";
    $result=mysql_query($sql);
    
    // Start looping rows in mysql database.
    while($rows=mysql_fetch_array($result)){
    ?>
    
    <table width="700" border="1" cellspacing="0" cellpadding="3" align="right">
    <tr>
    
    <td width="12%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['Member_No']; ?></td>
    <td width="13%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['Surname']; ?></td>
    <td width="13%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['Forename']; ?></td>
    <td width="40%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['Address']; ?></td>
    <td width="25%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['DOB']; ?></td>
    <td width="5%"  align="center" ><a href="member_delete.php">delete</a>
    </tr>
    </table>
    <br><br><br>
    <?
    // close while loop
    }
    
    // close connection
    mysql_close();
    ?>
    
    </body>
    </html>
    ------------------------------------------------------------------------------------------------------------------
    I get a delete button next to all the rows but when I click on the delete button I get a blank screen, the coding for the delete button is: -
    -------------------------------------------------------------------------------------------------------------------
    Code:
    <?php
    // this starts the session
    session_start();
    ?>
    
    <?php
    
    $db_name="project"; // Database name
    $tbl_name="member"; // Table name
    
    // Connect to server and select database.
    mysql_connect($_SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $memberno=urldecode($_GET['Member_No']);
    
    
    //$db->query("DELETE FROM $tbl_name WHERE Member_No = '$Member_No'";
    
    $query = ("DELETE FROM $tbl_name WHERE Member_No = '".$_GET["Member_No"]."' LIMIT 1");
    
    $result = mysql_query($query);
    
    //header("location: member_select.php");
    
    //$sql= "DELETE FROM $tbl_name WHERE Member_No = $memberno";
    
    //$result=mysql_query($sql);
    //echo "row deleted";
    
    // close connection
    mysql_close();
    ?>
    ---------------------------------------------------------------------------------------------------------------

    As you can see I have tried alot, could any one please help.

    Thank you in advanced
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    In the first form I see no delete button, no form and no form submission. So how do you pass the clicked record to be deleted to the delete script?

    Ronald

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      on line 71 where you have the delete button, shouldnt you be passing the $memberno through the url?

      Comment

      • flexsingh
        New Member
        • Mar 2008
        • 17

        #4
        Originally posted by markusn00b
        on line 71 where you have the delete button, shouldnt you be passing the $memberno through the url?
        I tried this
        [php]<a href="member_de lete.php?Member _No=<?php echo $rows['Member_No'];?>&something=e lse">delete</a>[/php]
        It works! ok it wasnt working before, thank you for your help sorry to have wasted your time, you must have good luck thank you again much appriciated.
        Last edited by ronverdonk; Mar 25 '08, 03:29 PM. Reason: code tags!!

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by flexsingh
          I tried this

          <a href="member_de lete.php?Member _No=<?php echo $rows['Member_No'];?>&something=e lse">delete</a>

          It works! ok it wasnt working before, thank you for your help sorry to have wasted your time, you must have good luck thank you again much appriciated.
          Not goodluck - just did the usual debugging :)

          See you around again!

          Comment

          • flexsingh
            New Member
            • Mar 2008
            • 17

            #6
            Originally posted by markusn00b
            Not goodluck - just did the usual debugging :)

            See you around again!
            :) will do thanks again

            Comment

            Working...