Jump to content

deleting a row in a php table?


Gazz1982

Recommended Posts

My php with mysql generates:

 

Delete

Name

Address

[] Checkbox

Bob

Down Town

[] Checkbox

Dave

Down Town

[] Checkbox

Tim

Down Town

For the Checkbox:

  echo "<td><form class='small' name='login' method='post'";
  echo "<input type='checkbox' name='Add' value='yes' /></td>";

 

I want to add 'yes' to my dispose column in my database, how do I update the database to the row which the checkbox is? ie If i check the box next to bob I want to add 'yes' to the dispose column only for Bob

 

The checkboxes are generated through a loop so all will have the same name

 

the mysql table as a unique id auto_increment primary key;

 

Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/109469-deleting-a-row-in-a-php-table/
Share on other sites

ok looks like what i need

 

echo "</table>";
echo"<br /><br />";
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($result2))
  {
  echo "<tr>";
  echo "<td><form class='small' name='login' method='post'>'";
  echo "<input type='checkbox' name='Delete' value='<?php echo  $rows['id']?>' /></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 "</table>";

 

just trying to figure out this bit - sorry I'm a bit of a novice - all help welcomed

$ids = join (',', $_POST['delID']);
$sql = "DELETE FROM docs WHERE docID IN ($ids)";   
mysql_query($sql);

if you ran this

 

$ids = join (',', $_POST['delID']);
$sql = "DELETE FROM docs WHERE docID IN ($ids)";
echo $sql;

 

you would see something like

 

DELETE FROM docs WHERE docID IN (1,5,8,9)

 

which would delete the 4 rows with those ids

ok so now im getting

 

delete    name  ID   

[]          Bob    1

[]          Dave  2

[]          Time  3

 

when the table is created where ID is $del which = $row['ID']

 

The value in the check box is also $del

[] = checkbox

 

so now if I run select * from login where ID = $del it should select all of the ones which were checked ???

 

Am I right or close?

your form code should be

<?php
echo "<form class='small' name='login' method='post'>'";                // Only ONE form

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($result2))
  {
  echo "<tr>";
  
  echo "<input type='checkbox' name='Delete[]' value='{$row['id']}' /></p></td>";     // NOTE the []
  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 "</table>";
echo "</form>";
?>

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.