Connecting Tech Pros Worldwide Forums | Help | Site Map

Deleting A Row in PHP

flexsingh's Avatar
Newbie
 
Join Date: Mar 2008
Posts: 17
#1: Mar 25 '08
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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // this starts the session 
  3. session_start(); 
  4. ?>
  5. <html>
  6.  
  7. <head>
  8. <h1><font face="sans-serif, Arial" font color="white">Members Page!</h1>
  9. </head>
  10.  
  11. <body background="main background1.jpg" link="yellow" vlink="yellow" hover="green" >
  12. <a href="blank.php">Back To Main page</a>
  13.  
  14. <table align="center" width="600" border="0" cellspacing="0" cellpadding="1" >
  15. <tr>
  16. <td><font face="sans-serif, Arial" color="white" size= "-1">DESC Order</td>
  17. <td><a href="member_select_md.php"><font face="sans-serif, Arial" font font size= "-1">Member DESC</a></td>
  18. <td><a href="member_select_sd.php"><font face="sans-serif, Arial" font font size= "-1">Surname DESC</a></td>
  19. <td><a href="member_select_fd.php"><font face="sans-serif, Arial" font font size= "-1">Forename DESC</a></td>
  20. <td><a href="member_select_ad.php"><font face="sans-serif, Arial" font font size= "-1">Address DESC</a></td>
  21. <td><a href="member_select_dd.php"><font face="sans-serif, Arial" font font size= "-1">DOB DESC</a></td>
  22. </tr>
  23. <tr>
  24. <td><font face="sans-serif, Arial" color="white" font font size= "-1">ASC Order</td>
  25. <td><a href="member_select.php"><font face="sans-serif, Arial" font size= "-1">Member ASC</a></td>
  26. <td><a href="member_select_sa.php"><font face="sans-serif, Arial" font size= "-1">Surname ASC</a></td>
  27. <td><a href="member_select_fa.php"><font face="sans-serif, Arial" font size= "-1">Forename ASC</a></td>
  28. <td><a href="member_select_aa.php"><font face="sans-serif, Arial" font size= "-1">Address ASC</a></td>
  29. <td><a href="member_select_da.php"><font face="sans-serif, Arial" font size= "-1">DOB ASC</a></td>
  30. </tr>
  31. </table>
  32. <br><br><br>
  33. <table align="right" width="700" border="1" cellspacing="0" cellpadding="3" >
  34. <tr>
  35.  
  36. <td align="center" width="12%"><b><u><font face="sans-serif, Arial" font color="white">Member No</b></u></td>
  37. <td align="center" width="13%"><b><u><font face="sans-serif, Arial" font color="white">Surname</b></u></td>
  38. <td align="center" width="13%"><b><u><font face="sans-serif, Arial" font color="white">Forename</b></u></td>
  39. <td align="center" width="40%"><b><u><font face="sans-serif, Arial" font color="white">Address</b></u></td>
  40. <td align="center" width="25%"><b><u><font face="sans-serif, Arial" font color="white">DOB</b></u></td>
  41. <td align="center" width="5%"></td>
  42. </tr>
  43. </table>
  44. <br><br><br><br>
  45. <?php
  46. $db_name="project"; // Database name
  47. $tbl_name="member"; // Table name
  48.  
  49. // Connect to server and select database.
  50. mysql_connect($_SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
  51. mysql_select_db("$db_name")or die("cannot select DB");
  52.  
  53. $memberno=urlencode($_GET['Member_No']);
  54.  
  55. // Retrieve data from database
  56. $sql="SELECT * FROM $tbl_name ORDER BY `Member_No` ASC";
  57. $result=mysql_query($sql);
  58.  
  59. // Start looping rows in mysql database.
  60. while($rows=mysql_fetch_array($result)){
  61. ?>
  62.  
  63. <table width="700" border="1" cellspacing="0" cellpadding="3" align="right">
  64. <tr>
  65.  
  66. <td width="12%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['Member_No']; ?></td>
  67. <td width="13%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['Surname']; ?></td>
  68. <td width="13%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['Forename']; ?></td>
  69. <td width="40%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['Address']; ?></td>
  70. <td width="25%" align="center"><font face="sans-serif, Arial" font color="white"><? echo $rows['DOB']; ?></td>
  71. <td width="5%"  align="center" ><a href="member_delete.php">delete</a>
  72. </tr>
  73. </table>
  74. <br><br><br>
  75. <?
  76. // close while loop
  77. }
  78.  
  79. // close connection
  80. mysql_close();
  81. ?>
  82.  
  83. </body>
  84. </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: -
-------------------------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // this starts the session
  3. session_start();
  4. ?>
  5.  
  6. <?php
  7.  
  8. $db_name="project"; // Database name
  9. $tbl_name="member"; // Table name
  10.  
  11. // Connect to server and select database.
  12. mysql_connect($_SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
  13. mysql_select_db("$db_name")or die("cannot select DB");
  14.  
  15. $memberno=urldecode($_GET['Member_No']);
  16.  
  17.  
  18. //$db->query("DELETE FROM $tbl_name WHERE Member_No = '$Member_No'";
  19.  
  20. $query = ("DELETE FROM $tbl_name WHERE Member_No = '".$_GET["Member_No"]."' LIMIT 1");
  21.  
  22. $result = mysql_query($query);
  23.  
  24. //header("location: member_select.php");
  25.  
  26. //$sql= "DELETE FROM $tbl_name WHERE Member_No = $memberno";
  27.  
  28. //$result=mysql_query($sql);
  29. //echo "row deleted";
  30.  
  31. // close connection
  32. mysql_close();
  33. ?>
---------------------------------------------------------------------------------------------------------------

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

Thank you in advanced

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Mar 25 '08

re: Deleting A Row in PHP


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
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,948
#3: Mar 25 '08

re: Deleting A Row in PHP


on line 71 where you have the delete button, shouldnt you be passing the $memberno through the url?
flexsingh's Avatar
Newbie
 
Join Date: Mar 2008
Posts: 17
#4: Mar 25 '08

re: Deleting A Row in PHP


Quote:

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_delete.php?Member_No=<?php echo $rows['Member_No'];?>&something=else">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.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,948
#5: Mar 25 '08

re: Deleting A Row in PHP


Quote:

Originally Posted by flexsingh

I tried this

<a href="member_delete.php?Member_No=<?php echo $rows['Member_No'];?>&something=else">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!
flexsingh's Avatar
Newbie
 
Join Date: Mar 2008
Posts: 17
#6: Mar 25 '08

re: Deleting A Row in PHP


Quote:

Originally Posted by markusn00b

Not goodluck - just did the usual debugging :)

See you around again!

:) will do thanks again
Reply