Jump to content

deleting a row


Gazz1982

Recommended Posts

This displays my table:

 

echo "<table border='1'>
<tr>
<th>Delete</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Password</th>
<th>Company</th>
<th>Address1</th>
<th>Address2</th>
<th>Address3</th>
<th>County</th>
<th>Country</th>
<th>Post Code</th>
<th>Phone Number</th>
<th>Validate</th>


</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><form class='small'>'";
  echo "<input type='checkbox' name='Delete' value='Delete' /></p></td>";
  echo "<td>" . $row['NAME_FIRST'] . "</td>";
  echo "<td>" . $row['NAME_LAST'] . "</td>";
  echo "<td>" . $row['EMAIL'] . "</td>";
  echo "<td>" . $row['PASSWORD'] . "</td>";
  echo "<td>" . $row['COMPANY'] . "</td>";
  echo "<td>" . $row['ADDRESS1'] . "</td>";
  echo "<td>" . $row['ADDRESS2'] . "</td>";
  echo "<td>" . $row['ADDRESS3'] . "</td>";
  echo "<td>" . $row['COUNTY'] . "</td>";
  echo "<td>" . $row['COUNTRY'] . "</td>";
  echo "<td>" . $row['POST_CODE'] . "</td>";
  echo "<td>" . $row['PHONE'] . "</td>";
  echo "<td>" . $row['VALIDATE'] . "</td>";
  
  echo "</tr>";
  echo "<input type='submit' name='Delete' value='Delete' target='delete.php?'/></p>";
  }
echo "</table>";

 

I have a check box titled delete once this is checked I want to pass everything from that row to delete.php where the whole row is delete. I have a column in the database called delete so I assume that I need to insert into login where (checkbox is ticked == true) using some kind of if statement - if checkbox ticked == true insert 'yes' into delete then delete * from login where delete ='yes'

 

How do I do this?

 

see www.noblesweb.co.uk/manager.php

 

Thanks

Link to comment
Share on other sites

Instead of having a field named "delete" in the database, use a uniqueID field. Do you have one that holds an auto-incremented ID? If you do, thats the field you should be using.

 

I put comments in the code

 

<?php

if (isset($_POST['delete_fields'])){

//delete all checked rows
$query = "DELETE FROM table_name WHERE id IN(".implode(",", $_POST['delete']).")";
$result = mysql_query($query)or die(mysql_error()."<p>With query:<br>$query");

echo "Rows Deleted<p>";

}

echo "<table border='1'>
<tr>
<th>Delete</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Password</th>
<th>Company</th>
<th>Address1</th>
<th>Address2</th>
<th>Address3</th>
<th>County</th>
<th>Country</th>
<th>Post Code</th>
<th>Phone Number</th>
<th>Validate</th>


</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><form class='small'>'";
  
  //You need to change the name to be an array, and the value should be your unique field.
  echo "<input type='checkbox' name='delete[]' value='{$row['UNIQUE_FIELD']}' /></p></td>";
  
  echo "<td>" . $row['NAME_FIRST'] . "</td>";
  echo "<td>" . $row['NAME_LAST'] . "</td>";
  echo "<td>" . $row['EMAIL'] . "</td>";
  echo "<td>" . $row['PASSWORD'] . "</td>";
  echo "<td>" . $row['COMPANY'] . "</td>";
  echo "<td>" . $row['ADDRESS1'] . "</td>";
  echo "<td>" . $row['ADDRESS2'] . "</td>";
  echo "<td>" . $row['ADDRESS3'] . "</td>";
  echo "<td>" . $row['COUNTY'] . "</td>";
  echo "<td>" . $row['COUNTRY'] . "</td>";
  echo "<td>" . $row['POST_CODE'] . "</td>";
  echo "<td>" . $row['PHONE'] . "</td>";
  echo "<td>" . $row['VALIDATE'] . "</td>";
  
  echo "</tr>";
  echo "<input type='submit' name='delete_fields' value='Delete' target='delete.php?'/></p>";
  }
echo "</table>";

?>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.