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
https://forums.phpfreaks.com/topic/109015-deleting-a-row/
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
https://forums.phpfreaks.com/topic/109015-deleting-a-row/#findComment-559236
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.